0
votes

I'm learning ios game programming and I need to create my own tile background - we're migrating an infinite-map style game from java.

I have the following code rendering our background tile graphics inside a loop:

SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"shallow_1.png"];
sprite.position = CGPointMake(x,y);
[self addChild:sprite];

However, I'm trying to find out how to properly batch render in spritekit. In java/opengl we'd apply the texture, add all the render positions, and then render everything at once - saving performance.

How can I properly batch render these tiles using spritekit? I can't find any information.

2
You can use SKTextureAtlas to preload textures, use zPosition to draw layers at once. That should help. - AndrewShmig
batching is automatic - if consecutive child sprites use the same texture and blend mode they will be batch drawn. Enable the debug labels to see # of draw calls - LearnCocos2D
Ok, so is there no harm then in calling SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"shallow_1.png"]; every single iteration of the loop? Seems unnecessary and in another languages we'd load it once, and clone. In opengl we apply the texture once, and just pass a list of vertices. - helion3
Seems like there is. Rendering a full background of these tiles (about 170 nodes) drops the FPS to 40. - helion3

2 Answers

0
votes

If you're planning to work with tilemaps, your best bet is KoboldKit.

It's a game engine for SpriteKit, and adds several features to the framework.

In includes support for time maps (Tiled Map Editor).

0
votes

Load your texture once:

SKTexture *texture = [SKTexture textureWithImageNamed:@"shallow_1.png"];

Then, make all of your SKSpriteNode objects referencing that texture:

// inside loop
SKSpriteNode *node = [SKSpriteNode spriteNodeWithTexture:texture];