Run two SKActions at once

空扰寡人 提交于 2019-11-30 05:57:43

Use a group action.

From sprite kit programming guide:

A group action is a collection of actions that all start executing as soon as the group is executed. You use groups when you want actions to be synchronized

SKSpriteNode *wheel = (SKSpriteNode*)[self childNodeWithName:@"wheel"];
CGFloat circumference = wheel.size.height * M_PI;
SKAction *oneRevolution = [SKAction rotateByAngle:-M_PI*2 duration:2.0];
SKAction *moveRight = [SKAction moveByX:circumference y:0 duration:2.0];
SKAction *group = [SKAction group:@[oneRevolution, moveRight]];
[wheel runAction:group];

A example in Swift would be:

    let textLabel = SKLabelNode(text: "Some Text")

    let moveTo = CGPointMake(600, 20)

    let big = SKAction.scaleTo(3.0, duration: 0.1)
    let med = SKAction.scaleTo(1.0, duration: 0.3)
    let reduce = SKAction.scaleTo(0.2, duration: 1.0)
    let move = SKAction.moveTo(moveTo, duration: 1.0)
    let fade = SKAction.fadeOutWithDuration(2.0)
    let removeNode = SKAction.removeFromParent()
    let group = SKAction.group([fade, reduce])

    let sequence = SKAction.sequence([big, med, move, group, removeNode])

    self.addChild(textLabel)
    textLabel.runAction(sequence)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!