我正在尝试添加一个基于两个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];

有任何想法吗?在此先多谢!

最佳答案

可能是您的定位详细信息,您确定它们是正确的吗?我对您的代码做了一些更改(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;
}

关于ios - iOS7中的SpriteKit animateWithTextures无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18894748/

10-14 21:05