本文介绍了如何从对象外部运行或执行SKAction?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码如下:

-(void) createBall {

    _ballSprite = [SKSpriteNode spriteNodeWithImageNamed:@"ball0001"];
    _ballSprite.position = CGPointMake(firstNode.position.x, firstNode.position.y);
     SKAction *ballScale =[SKAction scaleXTo:-0.5 duration:0];
     SKAction *ballMove = [SKAction moveByX:0 y:-300 duration:0];
     SKAction *ballMoveScale = [SKAction sequence:@[ballScale,ballMove];
     SKAction *ballScaleMove = [SKAction sequence:@[ballMove,ballScale]; //Unused variable
     [_ballSprite runAction:ballMoveScale];
     [self addChild:_ballSprite];

}

现在如何从外面运行let say ballScaleMove例如。在touchBegan处理程序内或在initWithSize ..etc。?

Now how do I run let say ballScaleMove from out side eg. inside the touchBegan handler or at initWithSize ..etc.?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

///here maybe
[_ballSprite runAction:ballScaleMove];  // Error undeclare identifier 'ballScaleMove';


}


推荐答案

您需要将属性或iVars定义为全局属性。在类的@interface中定义它们

You need to define your properties or iVars as global. define them in the @interface of your class

@interface
@property Class *myProperty;
@end

然后你可以使用self.myProperty或_myProperty访问它们(访问隐式iVar为您的财产)

Then you can access them with self.myProperty or _myProperty (accessing the implicit iVar for your property)

我希望它有所帮助

这篇关于如何从对象外部运行或执行SKAction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 02:54