Op dit moment bezig met een nieuw, leuk, projectje. Ik kan er nog niet te veel over vertellen, maar hiervoor maak ik ook gebruik van sprite animations, het leek mij handig om hiervoor een aparte class voor te maken, GHBSpriteAnimationLayer. Je kan in één sprite meerdere animaties ‘klaar’ zetten en deze afspelen op het gewenste moment. De subclass is CALayer, er wordt dus gebruik gemaakt van Core Animation. De animatie gaat hierdoor erg soepel, uiteraard afhankelijk van de afbeelding (duh).
Ik heb op Github de bron code, incl. een voorbeeld sprite gedeeld.
Het gebruik is heel simpel:
// setup sprite source image CGImageRef imgRef = [UIImage imageNamed:@"sprite-large.png"].CGImage; // setup display size CGSize displaySize = CGSizeMake( 120, 124 ); // size of one frame // setup GHBSpriteAnimationLayer GHBSpriteAnimationLayer *spriteAnimation = [[GHBSpriteAnimationLayer alloc] initWithSprite:imgRef withSize:displaySize]; // add to self.view.layer spriteAnimation.position = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2); [self.view.layer addSublayer:spriteAnimation]; // add animation [spriteAnimation addSpriteAnimationWithName:@"default" withFrames:1,2,3,4,5,6,0]; // add another animation [spriteAnimation addSpriteAnimationWithName:@"test" withFrames:1,3,0]; // play animation 'default' [spriteAnimation playSpriteAnimationWithName:@"default" atFramerate:12 looping:YES]; // stop animation // [spriteAnimation stopSpriteAnimation];