你能把SKAction放在if语句中吗?

时间:2014-05-10 02:26:39

标签: objective-c ios7 sprite-kit skaction

这是我真正想要的论点,但它不会起作用。这样做的正确方法是什么? 任何想法?

if (targetWithinRange == NO) {

      SKAction *move = [SKAction moveToX:-30 duration:1]; //Warning Unused Variable 'move'

}else{ //or if the target is within rang then go and hit the target

      SKAction *move = [SKAction moveTo:(CGPointMake(target.position.x, target.position.y)) duration:1];//Warning Unused Variable 'move'
 }    



 SKAction *lookingForTheTarget = [SKAction sequence:@[someAction,move,anotherAction]];

[ourSprite runAction:lookingForTheTarget];

1 个答案:

答案 0 :(得分:2)

移动范围仅在if声明中。

您应该将其移出if

SKAction *move;
if (targetWithinRange == NO) {
    move = ...
}
else {
    move = ...
}