Frankeex Frankeex - 1 year ago 72
iOS Question

How to pulse a sprite using SpriteKit in SWIFT

I am attempting to "pulse" a sprite in SK/SWIFT. My attempts were crude using For-loops and setScale but were not working (no errors - just no animation). I feel that using SKActions would perhaps be more elegant. After using some help from below here is my current implementation. However, it is coming up with errors on compiling;
Expected member name or constructor call after type name &
Consecutive statement on a line must be separated by a ;

Here is the code I am using

SKAction *pulseUp = [SKAction.scaleTo(3.0, duration: 3.0)]
SKAction *pulseDown = [SKAction.scaleTo(1.0, duration: 3.0)]
SKAction *pulse = [SKAction.sequence(pulseUp, pulseDown)]
SKAction *repeat = [SKAction repeatActionForever:pulse]]
[self.playButton runAction: repeat]


Any help would be greatly appreciated.

Answer Source

In xCode Version 8.3.3 with Swift,

    let pulseUp = SKAction.scale(to: 3.0, duration: 1.0)
    let pulseDown = SKAction.scale(to: 0.5, duration: 1.0)
    let pulse = SKAction.sequence([pulseUp, pulseDown])
    let repeatPulse = SKAction.repeatForever(pulse)
    self.playButton.run(repeatPulse)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download