NSBSpritesheetLayer 1.0.1

NSBSpritesheetLayer 1.0.1

TestsTested
LangLanguage Obj-CObjective C
License WTFPL
ReleasedLast Release Dec 2014

Maintained by Nacho Soto.



  • By
  • Nacho Soto

This projects enables you to use spritesheet images for animations under UIKit, in a similar way as you would do in Cocos2D or other game frameworks.

To start, you need to create an instance of NSBSpritesheet. You can do this, for example, by using NSBTexturePackerSpritesheetFactory by passing the parsed JSON and image generated by TexturePacker.

NSDictionary *spritesheets = [[NSBTexturePackerSpritesheetFactory factory] spritesheetsWithAnimationsData:data image:image];

The returned dictionary contains all the different animations in the spritesheet. You can now get an individual spritesheet with its name:

NSBSpritesheet *spritesheet = spritesheets[@"Animation"];

Once you have that Spritesheet object you can create the layer:

[[NSBSpritesheetLayer alloc] initWithSpritesheet:spritesheet framesPerSecond:30];

This is a subclass of CALayer, which means you can set it as a sublayer (- [CALayer addSublayer:]) or set it as your view layer (+ [UIView layerClass]). This class has two methods - (void)animate and - (void)stop, which will render the spritesheet at the specified frames per second.