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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With