简体   繁体   English

iOS7中的SpriteKit animateWithTextures无法正常工作

[英]SpriteKit animateWithTextures in iOS7 not working

I'm trying to add a little animation based on two pngs, where I create two SKTextures with two images and create an SKAction, and have it run forever with [SKAction repeatActionForever] but nothing is happening, nothing is appearing on the screen. 我试图添加一个基于两个png的小动画,在其中创建带有两个图像的两个SKTextures并创建一个SKAction,并使其与[SKAction repeatActionForever]一起永久运行,但是没有任何反应,屏幕上也没有任何显示。

Here's my code: 这是我的代码:

_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];

Any ideas? 有任何想法吗? Thanks a lot in advance! 在此先多谢!

could be your positioning details, are you sure they are correct? 可能是您的定位详细信息,您确定它们是正确的吗? I've changed your code slightly (self.frame.size.width instead of screenWidth and the same for height, to position it in the centre of the view) and it works for me: 我已经稍微更改了您的代码(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;
}

So my problem was, actually, my own ignorance, since I first was adding my SKNodes , and the last, when the background should have been added the first, so it could be on the background :) 所以我的问题实际上是我自己的无知,因为我首先添加了我的SKNodes ,最后一次是应该在背景中添加第一个SKNodes ,所以它可能在背景中:)

thanks a lot everybody for the answers! 非常感谢大家的回答!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM