iOS SpriteKit动画无效

时间:2016-05-09 11:49:13

标签: ios iphone animation sprite-kit

我是iOS原生游戏开发的新手。我正在尝试使用一些帧为角色创建理想状态的动画。我正在关注Ray's Website的教程。看起来我做的一切都很好,但我看不到动画在工作。只有第一帧(默认)始终可见。我调试代码&它确实正在访问闪烁播放器方法,其中所有3帧也存在,但屏幕上没有任何事情发生。

如果有人可以指导/帮助我确定问题,那将会很棒。

@implementation GameScene
{
    NSArray *_playerBlinkFrames;
}

// Player
SKNode *_player;

-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {

        [self createPlayer];    
}
    return self;
}

- (void) createPlayer
{
    SKTextureAtlas *playerAnimatedAtlas = [SKTextureAtlas atlasNamed:@"Assets"];
    _player = [SKNode node];
    SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Idle"];
    [_player addChild:sprite];

    [sprite setName:@"Ball"];

    NSMutableArray *blinkFrames = [NSMutableArray array];

    SKTexture *temp = [playerAnimatedAtlas textureNamed:@"Idle.png"];
    SKTexture *temp2 = [playerAnimatedAtlas textureNamed:@"Blink.png"];
    SKTexture *temp3 = [playerAnimatedAtlas textureNamed:@"LookRight.png"];


    [blinkFrames addObject:temp];
    [blinkFrames addObject:temp2];
    [blinkFrames addObject:temp3];

    _playerBlinkFrames = blinkFrames;
    _player.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
    [self addChild:_player];
    [self blinkingPlayer];
}

-(void)blinkingPlayer
{
    [_player runAction:[SKAction repeatActionForever:
                      [SKAction animateWithTextures:_playerBlinkFrames
                                       timePerFrame:0.3f
                                             resize:NO
                                            restore:YES]] withKey:@"blinkingInPlacePlayer"];

    return;
}

感谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

// Player
SKSpriteNode *_player;

//..//
SKTextureAtlas *playerAnimatedAtlas = [SKTextureAtlas atlasNamed:@"Assets"];

NSMutableArray *blinkFrames = [NSMutableArray array];

SKTexture *temp = [playerAnimatedAtlas textureNamed:@"Idle.png"];
SKTexture *temp2 = [playerAnimatedAtlas textureNamed:@"Blink.png"];
SKTexture *temp3 = [playerAnimatedAtlas textureNamed:@"LookRight.png"];


[blinkFrames addObject:temp];
[blinkFrames addObject:temp2];
[blinkFrames addObject:temp3];

_playerBlinkFrames = blinkFrames;

SKTexture *tempSprite = _playerBlinkFrames[0];
_player = [SKSpriteNode spriteNodeWithTexture:tempSprite];

我没有测试过,但我认为你已经创建了一个由spritenode覆盖的SKNode播放器。

让我知道