Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of UIImageView animationImages in SpriteKit?

I'm experimenting with SpriteKit, I'm building a humanoid character who uses multiple image files for facial expressions. So I can build up an SKSpriteNode to depict this character using a series of other sprites, i.e nodes for each arm and legs and the head, but I want to use multiple nodes for the face. In standard UIKit, you can use a UIImageView with an array of images and it will automatically animate through that array with the duration you set.

NSArray *animationArray = [NSArray arrayWithObjects:
                                      [UIImage imageNamed:@"image1.jpg"],
                                      [UIImage imageNamed:@"image2.jpg"],
                                      ..., nil];

UIImageView *animationView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 400, 260)];

[self.view addSubview:animationView];    

animationView.animationImages=animationArray;
animationView.animationDuration=1.5;
animationView.animationRepeatCount=0;

[animationView startAnimating]; 

What would be the equivalent in SpriteKit?

like image 306
Toby Avatar asked Nov 16 '13 03:11

Toby


1 Answers

You can use SKAction to create animations, like this:

SKAction *animation = [SKAction animateWithTextures:_animationArray timePerFrame:0.1];
[self runAction:animation withKey:@"myAnimation"]; // self is e.g. SKSpriteNode object

SKAction class reference

SKNode class reference (Running Actions)

like image 189
juniperi Avatar answered Oct 24 '22 03:10

juniperi