加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 在两个或更多SKSpriteNode上同步SKActions?

发布时间:2020-12-14 18:03:49 所属栏目:百科 来源:网络整理
导读:我想同步移动两个(或更多)SKSpriteNodes.任何差异都会显示出来我试图按顺序触发每个精灵的SKAction,当最后一个精灵完成时,它会触发一个新的动作.但事实证明,这些动作并没有以它们开始的相同顺序结束,这导致了一个明显的时间差异. 有没有办法在两个或多个具有
我想同步移动两个(或更多)SKSpriteNodes.任何差异都会显示出来我试图按顺序触发每个精灵的SKAction,当最后一个精灵完成时,它会触发一个新的动作.但事实证明,这些动作并没有以它们开始的相同顺序结束,这导致了一个明显的时间差异.

有没有办法在两个或多个具有持续时间的精灵上运行并行SKActions,以便它们在完全相同的时间结束或者至少以它们的启动顺序结束?

这是一个不起作用的原则示例:

- (void)testMethod1{
SKSpriteNode *child_1=[arrayWithSprites objectAtIndex:1];
SKSpriteNode *child_2=[arrayWithSprites objectAtIndex:2];

//This doesn't work.
[child_1 runAction:[SKAction moveToX:20.0 duration:0.5]];
[child_2 runAction:[SKAction moveToX:20.0 duration:0.5] 
    completion:^{[self testMethod1];}];
//Actions might not be finished in the order they are started.
}

这是我尚未尝试的一种方式,但想知道它是否可以解决我的问题:

- (void)testMethod2{
SKSpriteNode *child_1=[arrayWithSprites objectAtIndex:1];
SKSpriteNode *child_2=[arrayWithSprites objectAtIndex:2];

//Will this guarantee total syncronisation?
[self runAction:[SKAction group:[NSArray arrayWithObjects:
                                 [SKAction runBlock:^{[child_1 runAction:[SKAction moveToX:20.0 duration:0.5]];}],[SKAction runBlock:^{[child_2 runAction:[SKAction moveToX:20.0 duration:0.5]];}],nil]]
      completion:^{[self testMethod2];}];
}

我希望我的英语和思想是可以理解的.

// Micke ….

解决方法

只需添加一个容器SKNode,然后它们将立即移动:

SKNode *containerNode = [[SKNode alloc] init];    
[containerNode addChild:node1];    
[containerNode addChild:node2]; //add as many as necessary    
[containerNode runAction:someAction]; //declare the action you want them both to perform

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读