iOS7中的SpriteKit animateWithTextures无法正常工作

时间:2013-09-19 12:33:58

标签: ios animation ios7 sprite-kit

我正在尝试添加一个基于两个png的小动画,我在其中创建两个带有两个图像的SKTextures并创建一个SKAction,并使用[SKAction repeatActionForever]让它永远运行但没有任何事情发生,没有任何内容出现在屏幕。

这是我的代码:

_planePropeller = [SKSpriteNode spriteNodeWithImageNamed:@"PLANE PROPELLER 1.png"];
        _planePropeller.xScale = 0.2;
        _planePropeller.yScale = 0.2;
        _planePropeller.position = CGPointMake(screenWidth/2, _plane.size.height+10);
        SKTexture *propeller1 = [SKTexture textureWithImageNamed:@"PLANE PROPELLER 1.png"];
        SKTexture *propeller2 = [SKTexture textureWithImageNamed:@"PLANE PROPELLER 2.png"];
        SKAction *spin = [SKAction animateWithTextures:@[propeller1, propeller2] timePerFrame:0.1];
        SKAction *spinForever = [SKAction repeatActionForever:spin];
        [_planePropeller runAction:spinForever];
        [self addChild:_planePropeller];

有什么想法吗?非常感谢提前!

2 个答案:

答案 0 :(得分:1)

可能是您的定位细节,您确定它们是正确的吗?我稍微更改了你的代码(self.frame.size.width而不是screenWidth,高度相同,将它放在视图的中心),它对我有用:

- (SKNode *)propellorNode
{
SKNode *planePropeller = [SKSpriteNode spriteNodeWithImageNamed:@"image1.png"];
planePropeller.xScale = 0.2;
planePropeller.yScale = 0.2;
planePropeller.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
SKTexture *propeller1 = [SKTexture textureWithImageNamed:@"image1.png"];
SKTexture *propeller2 = [SKTexture textureWithImageNamed:@"image2.png"];
SKAction *spin = [SKAction animateWithTextures:@[propeller1, propeller2]    timePerFrame:0.1];
SKAction *spinForever = [SKAction repeatActionForever:spin];
[planePropeller runAction:spinForever];
return planePropeller;
}

答案 1 :(得分:-1)

所以我的问题实际上是我自己的无知,因为我第一次添加我的SKNodes,最后,当背景应该添加第一个,所以它可能在后台:)< / p>

非常感谢大家的答案!