SpriteKit:如何实现touchesBegan和touchesEnded将动作分成两部分?

时间:2014-04-29 12:43:32

标签: ios game-physics

我正在尝试做一个小小的射箭游戏,目前我有一个基本的touchesBegan方法,使用SKActions为弓箭手制作动画并射箭。

我很难得到它以便我保持触摸以画出弓,然后当我释放时,动画的其余部分播放并且箭射出。

我尝试使用两个单独的NSMutableArray地图集分布在touchesBegantouchesEnded方法上并带有userInteractionEnabled标记,但这有点不合适......

最终,我希望暂停的持续时间决定applyImpulse:CGVectorMake的值。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
SKNode *archerNode = [self childNodeWithName:@"archerNode"];

if (archerNode != nil)
 {
    SKAction *draw = [SKAction animateWithTextures:self.archerDraw timePerFrame:0.075];
    [archerNode runAction:draw];

    SKAction *shootArrow = [SKAction runBlock:^{

        SKNode *arrowNode = [self createArrowNode];

        [self addChild:arrowNode];
        [arrowNode.physicsBody applyImpulse:CGVectorMake(20.0, 0)];
    }];

    SKAction *sequence = [SKAction sequence:@[draw, shootArrow]];

    [archerNode runAction:sequence];
   }
  }

1 个答案:

答案 0 :(得分:0)

touchesBegan:部分&部分中启动充电动画。移动touchesEnded:(+ touchesCancelled:)函数中的箭头释放代码。在实例变量中保持触摸开始的时间将帮助您计算脉冲向量。