iOS 7 Sprite Kit在SKAction中更改zPosition

时间:2014-02-04 21:57:09

标签: ios objective-c ios7 sprite-kit

我有两个不同的SKSpriteNodes。第一个是静止的,第二个是我想要绕第一个节点移动。我的第二个节点从屏幕外飞来,zPosition为11(第一个节点的zPosition为10)。当第二个节点飞到屏幕的另一端时,我让节点翻转并飞回。目前我想将zPosition更改为9。

witch.position = CGPointMake(self.size.width + 200, self.size.height / 2 + 50);
witch.zPosition = 11;
[self addChild:witch];

SKAction *moveLeft = [SKAction moveToX:-200 duration:8];
SKAction *moveRight = [SKAction moveToX:self.size.width + 200 duration:8];
SKAction *moveDown = [SKAction moveToY:secondNode.position.y - 50 duration:0.3];
SKAction *moveUp = [SKAction moveToY:secondNode.position.y + 50 duration:0.3];
SKAction *flipRight = [SKAction scaleXTo:-1 duration:0];
SKAction *flipLeft = [SKAction scaleXTo:1 duration:0];
[secondNode runAction:
  [SKAction repeatActionForever:
      [SKAction sequence:
         @[moveLeft, moveDown, flipRight, CHANGEZPOSITIONHERE, moveRight, moveUp, flipLeft, CHANGEZPOSITIONHERE]]]];

如何更改zPosition中间的SKAction

提前感谢您提供所有建议和帮助。

1 个答案:

答案 0 :(得分:0)

由于LearnCocos2D评论,我找到了这个答案。

添加runBlock:action我能够更改zPosition。最终的代码是:

[secondNode runAction:
 [SKAction repeatActionForever:
  [SKAction sequence:
     @[moveLeft, moveDown, flipRight, 
         [SKAction runBlock:(dispatch_block_t)^(){
               secondNode.zPosition = 9;
          }], moveRight, moveUp, flipLeft, 
         [SKAction runBlock:(dispatch_block_t)^(){
               secondNode.zPosition = 11;
          }]]]]];