How to create a pulse effect on SKSpriteNode?

Hi would like to know how to create a visual impulse effect like in the video below.

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

I followed the link posted in the video; however, I was unable to achieve the same effect. I am having problems with SKSpriteNode.

Preferably, I would like to be able to loop this effect to repeat every second or so.

Any help would be much appreciated! Thank!

+3


source to share


1 answer


The real easy way to do this would be to have your button image and a framed image right below you. then just run the heart rate control feature on the button outline image and voila! It works with any shape and you can just adjust the actions as you see fit. They are added through the scene editor, but it doesn't matter how they are added as long as the outline images have a lower zPosition than the button.

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)
    }
}

      

+6


source







All Articles