objective-c - 同时运行两个 SKAction

标签 objective-c xcode sprite-kit skaction

我正在使用一个序列来运行 SKActions 列表。然而,我想做的是运行一个 SKAction,然后一次运行两个,然后按顺序运行一个。

这是我的代码:

SKNode *ballNode = [self childNodeWithName:@"ball"];

    if (ballNode != Nil){
        ballNode.name = nil;

        SKAction *delay = [SKAction waitForDuration:3];
        SKAction *scale = [SKAction scaleTo:0 duration:1];
        SKAction *fadeOut = [SKAction fadeOutWithDuration:1];
        SKAction *remove = [SKAction removeFromParent];

        //put actions in sequence
        SKAction *moveSequence = [SKAction sequence:@[delay, (run scale and fadeout at the same time), remove]];

        //run action from node (child of SKLabelNode)
        [ballNode runAction:moveSequence];
    }

我怎样才能做到这一点?我假设我不能使用序列?

最佳答案

使用群组操作。

来自 Sprite 套件编程指南:

组操作是一组操作,所有操作在组执行后立即开始执行。当您希望同步操作时可以使用组

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];

关于objective-c - 同时运行两个 SKAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40395456/

相关文章:

objective-c - 使用 Core Data 时是否可以使用复杂索引?

objective-c - 如何用文档装饰 Objective C 方法?

ios - 适用于 iOS 的 Google Places API 与 Google Places Web 服务

objective-c - 如何使用 SpriteKit Physics Joint Limit 制作绳索?

ios - UISearchDisplayDelegate 弃用解决方法

ios - 使用 UICollectionView 时 UITableView 的 NSInternalInconsistencyException?

Xcode UI 测试 - 拖放

ios - SKAction.moveToX 重复值更改

ios - Spritekit SKNode 大小百分比

objective-c - 无法访问 ivar CGPDFPageRef