PIOSpriteKit is a utility library for Apple's SpriteKit. It's goal is to eliminate some boilerplate code and add some usefull components.
Simply add the files in the PIOSpriteKit/Classes to your project. You will also need to link your project with SpriteKit.framework.
If you use CocoaPods, just include following line in your Pod file:
pod 'PIOSpriteKit'
PIOScrollSceneViewController lets you scroll and zoom your scene. It consists of two main classess: PIOScrollScene
and PIOScrollSceneViewController
. The setup is really simple:
First of all setup your scene
-
Make sure your scene inherits from
PIOScrollViewScene
@interface ExampleScrollScene : PIOScrollScene
-
Initialize
rootNode
property of your scene with aSKSpriteNode
you wish to pan and zoom.[PIOScrollScene rootNode]
is the main node of the scene.- (instancetype)initWithSize:(CGSize)size { if([super initWithSize:size] != nil) { self.rootNode.texture = [SKTexture textureWithImageNamed:@"sample_image.jpg"]; self.rootNode.size = self.rootNode.texture.size; } return self; }
-
Override
PIOScrollScene
properties that let's you specify minimum maximum and initial zoom zcale (1 is a default value)- (CGFloat)minimumZoomScale { return 0.5; } - (CGFloat)maximumZoomScale { return 1.0; } - (CGFloat)initialZoomScale { return 0.5; }
Setup your view controller
-
Make sure your view controller inherits from
PIOScrollSceneViewController
@interface ExampleScrollViewController : PIOScrollSceneViewController
-
Present your scene using
presentScene
method.- (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; if (self.sampleScene == nil) { //[PIOScrollSceneViewController spriteKitView] is an IBOutlet so you can hook it up to your SKView in the storyboard) self.sampleScene = [[ExampleScrollScene alloc] initWithSize:self.spriteKitView.frame.size]; [self presentScene:self.sampleScene]; } }
PIOTiledNode lets you create node that consists of several tiles.
Setup your tile node
-
Make sure your node inherits from
PIOTiledNode
@interface ExampleTiledNode : PIOTiledNode
-
Override
PIOTiledNode
properties that let's you specify number of rows the node consists of- (uint)rowsCount { return 1; } - (uint)columnsCount { return 2; }
-
Override
imageFileNameForRow:column
method, that returns tile file name for given row and column- (NSString *)imageFileNameForRow:(NSUInteger)row column:(NSUInteger)column { return [NSString stringWithFormat:@"sample_image_%lu%lu.jpg", (unsigned long) row, (unsigned long) column]; }
Use your tiled node
-
Call
[PIOTiledNode load]
method to load your tile nodeSKSpriteNode *sampleNode; sampleNode = [[[ExampleTiledNode alloc] init] load];
-
Use it as any other node
You can find the working example app in Examples folder. Enjoy!
PIOSpriteKit is under MIT License