简体   繁体   中英

SKAction scaleBy: duration: SpriteKit

I have a trouble trying to make one circle big and small using [SKAction scaleBy: duration:]

SKAction *scaleDown = [SKAction scaleBy:0.2 duration:1.8];  
SKAction *scaleUp= [scaleDown reversedAction];
SKAction *fullScale = [SKAction sequence:@[scaleDown, scaleUp, scaleDown, scaleUp]];
[_circleChanging runAction:fullScale];

What I get is the circle becoming so small that disappears and then doesn't come back. It has to become small and then come back to his original size doing it 2 times.

Try:

  SKAction *scaleDown = [SKAction scaleTo:0.2 duration:0.75];
       SKAction *scaleUp= [SKAction scaleTo:1.0 duration:0.75];
       SKAction *fullScale = [SKAction repeatActionForever:[SKAction sequence:@[scaleDown, scaleUp, scaleDown, scaleUp]]];
       [_circleChanging runAction:fullScale];

Not all actions are reversible, and the reverse sometimes doesn't mean "go back to the original value".

If you check the documentation , the reverse action of scaleBy is actually scaling to -0.2 in your case. Just create a new scale action instead of reversing.

Also try making a copy of the actions for the 2nd use:

SKAction *fullScale = [SKAction sequence:
                       @[scaleDown, scaleUp, [scaleDown copy], [scaleUp copy]]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM