Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 they 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 compile errors;

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.

like image 566
Frankeex Avatar asked Oct 26 '25 10:10

Frankeex


1 Answers

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)
like image 96
Frankeex Avatar answered Oct 29 '25 01:10

Frankeex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!