clear
clear

Reputation: 1

SpriteKit animation error

I want to make the hero to animation when he jumps

 NSArray *animatedImages = [NSArray arrayWithObjects:
                                   [UIImage imageNamed:@"hero_1.png"],
                                   [UIImage imageNamed:@"hero_2.png"],
                                   [UIImage imageNamed:@"hero_1.png"],
                                   [UIImage imageNamed:@"hero_.png"], nil];
    SKAction *jump = [SKAction animateWithTextures:animatedImages timePerFrame:0.2];
    [hero runAction:jump];

This code is placed in didBeginContact

The error

-[UIImage isRotated]: unrecognized selector sent to instance

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage isRotated]: unrecognized selector sent to instance 0x1780945a0'

Upvotes: 0

Views: 483

Answers (1)

CodeSmile
CodeSmile

Reputation: 64477

You can't animate UIImage objects, they have to be SKTexture objects.

NSArray *animatedImages = [NSArray arrayWithObjects:
                               [SKTexture textureWithImageNamed:@"hero_1.png"],
                               [SKTexture textureWithImageNamed:@"hero_2.png"],
                               [SKTexture textureWithImageNamed:@"hero_1.png"],
                               [SKTexture textureWithImageNamed:@"hero_.png"], nil];

Upvotes: 2

Related Questions