加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 如何在SKSpriteNode上创建脉冲效果?

发布时间:2020-12-14 04:48:34 所属栏目:百科 来源:网络整理
导读:您想了解如何创建视觉脉冲效果,如下面的视频中所示. https://www.youtube.com/watch?v=uiHj-KZWjpU 我按照视频中发布的链接;但是,我无法达到同样的效果.我在使用SKSpriteNode时遇到了麻烦. 我希望能够循环这种效果,每隔一秒左右重复一遍. 任何帮助将非常感谢
您想了解如何创建视觉脉冲效果,如下面的视频中所示.

https://www.youtube.com/watch?v=uiHj-KZWjpU

我按照视频中发布的链接;但是,我无法达到同样的效果.我在使用SKSpriteNode时遇到了麻烦.

我希望能够循环这种效果,每隔一秒左右重复一遍.

任何帮助将非常感谢!谢谢!

解决方法

这样做的一个简单方法是将按钮图像和按钮下方的轮廓图像放在一起.然后只需在按钮轮廓图像上运行脉冲功能即可!它适用于任何形状,您可以根据需要调整动作.这些是通过场景编辑器添加的,但只要轮廓图像的zPosition低于按钮,它们的添加方式就没有区别.

enter image description here

button1


button1_outline


button2


enter image description here


enter image description here


enter image description here

class LevelMenu: SKScene {

    private var button1 = SKSpriteNode()
    private var button1Outline = SKSpriteNode()
    private var button2 = SKSpriteNode()
    private var button2Outline = SKSpriteNode()
    private var button3 = SKSpriteNode()
    private var button3Outline = SKSpriteNode()

    override func didMove(to view: SKView) {

        if let button1 = self.childNode(withName: "button1") as? SKSpriteNode {
            self.button1 = button1
        }

        if let button2 = self.childNode(withName: "button2") as? SKSpriteNode {
            self.button2 = button2
        }

        if let button3 = self.childNode(withName: "button3") as? SKSpriteNode {
            self.button3 = button3
        }

        if let button1Outline = self.childNode(withName: "button1Outline") as? SKSpriteNode {
            self.button1Outline = button1Outline
        }

        if let button2Outline = self.childNode(withName: "button2Outline") as? SKSpriteNode {
            self.button2Outline = button2Outline
        }

        if let button3Outline = self.childNode(withName: "button3Outline") as? SKSpriteNode {
            self.button3Outline = button3Outline
        }
    }

    func pulseAction(node: SKSpriteNode) {

        let copyNode = node.copy() as! SKSpriteNode
        copyNode.position = node.position
        addChild(copyNode)

        let scale = SKAction.scale(by: 1.75,duration: 0.4)
        scale.timingMode = .easeInEaSEOut
        let wait = SKAction.wait(forDuration: 0.25)
        let fadeOut = SKAction.fadeOut(withDuration: 0.15)
        let fadeSeq = SKAction.sequence([wait,fadeOut])
        let pulseGroup = SKAction.group([scale,fadeSeq])

        copyNode.run(pulseGroup,completion: { copyNode.removeFromParent() })
    }

    override func touchesBegan(_ touches: Set<UITouch>,with event: UIEvent?) {

        pulseAction(node: button1Outline)
        pulseAction(node: button2Outline)
        pulseAction(node: button3Outline)
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读