3

I've made a Tiled game. Right now I'm stress testing my phone's capabilities by increasing amount of nodes in the scene. There's physics based stuff, AI movement, Day & Night system, particles popping out here & there & plenty of other stuff going on under the hood for my scenes. What I want to know is there a performance difference in using 16x16 tiles, what I have now, versus using 32x32 tiles? These tiles are basically just an image that was added to the scene; they don't have any physics bodies or anything else of that sort. They do have properties I set upon them when making the map in Tiled, but I don't think that has any performance impact. Each map has several layers (background, vegetation, spawn points, buildings, sometimes a few more). Here is a code snippet of how tiles are rendered for 1 such layer:

        if([map propertiesForGid:tileGid][@"shrub"])
        {
            SKSpriteNode *tile = [layer tileAtCoord:coord];
            tile.name = @"vegShrub";
            [self addChild:tile];
        }
        else if([map propertiesForGid:tileGid][@"tree"])
        {
            SKNode *tile = [[Breakable alloc] initWithWhole:[atlas textureNamed:@"tree"] broken:[atlas textureNamed:@"tree-stump"]];
            tile.position = [self pointForCoord:coord];
            [self addChild:tile];
            [layer removeTileAtCoord:coord];
        }

If I use 32x32 tiles over my current 16x16 tiles, will I somehow free up some memory or "relieve the load" off the system?

Krekin
  • 1,516
  • 1
  • 13
  • 24
  • It probably won't make a difference since you'll be drawing the same amount of pixels (fillrate). It can make a difference if you enumerate the tile sprites every frame and have an inefficiency in that render loop or you're doing crazy stuff to every sprite every frame. – CodeSmile Jun 14 '15 at 21:24

1 Answers1

4

With tile maps, each tile is usually represented by a SKSpriteNode. So if your map is 320 x 320 and you're using 32x32 tiles, you will end up with 100 nodes. Using 16x16 tiles on the same map size will result in 400 nodes. The more nodes, the greater the load.

On another note, you should look into getting the SKAToolKit to parse tile maps in your app. It's open source, free and has a ton of built in features such as auto follow, mini map, etc...

sangony
  • 11,636
  • 4
  • 39
  • 55
  • 1
    I think your logic is solid and I agree with you. Regarding the link you attached...HOLY SH*T! That is exactly what I needed and more! Thank you very much. – Krekin Jun 12 '15 at 17:56
  • 1
    @Krekin - Glad to be of help. – sangony Jun 12 '15 at 18:07
  • 2
    Note though that `SKATiledMap` is actually also making an `SKSpriteNode` for each tile, which is a very inefficient way of rendering the map. If you need better performance (and more complete support for Tiled features), you should try TilemapKit - http://tilemapkit.com/ – Thorbjørn Lindeijer Jun 12 '15 at 20:18
  • 1
    @ThorbjørnLindeijer Love Tiled and thanks for making such a great product. I am the developer on SKATK and would love talk more about what you do/don't like as the SKATiledMap is made to work with your product. The link you provided in the credit section "TilemapKit is a project by frustrated tilemap game developers Steffen Itterheim (aka LearnCocos2D, author of Learn Cocos2D and Learn SpriteBuilder) and Marcus Lubczyk." Is the same reason I made SKA stuff. Feel free to email me to discuss outside of SO. SKATK isn't just for Tiled but I would like to make the best toolkit for Sprite Kit devs. – Skyler Lauren Jun 12 '15 at 21:04
  • 1
    @ThorbjørnLindeijer Could you be more explicit on why this is very inefficient to associate one `SKSpriteNode` for each tile? – Dominique Vial Jun 13 '15 at 11:48
  • @ThorbjørnLindeijer Thanks for the recommendation. I have heard about TilemapKit. Registered in the forums and keeping tabs on your API. But I'm a game developer with a 0 budget. So unfortunately paying $49-$99 (I believe that is the price range your team specified) is out of the question for me currently. But maybe one day. – Krekin Jun 13 '15 at 20:30
  • @SkylerLauren Sorry I didn't mean to say I did not like `SKATiledMap`. Its functionality just seemed incomplete (only orthogonal maps, for example) and the rendering approach with a node for each tile can't be the fastest way. Of course I appreciate you making such a library available for free. I'll contact you outside SO. – Thorbjørn Lindeijer Jun 13 '15 at 20:43
  • @Domsware Using one `SKSpriteNode` for each tile means allocating lots of small pieces of memory and it creates a lot of work for the rendering backend, with each node having its own transformations, blend modes, etc. For fast rendering of a tile map, you'll want to create a geometry mesh per layer/tileset that needs to be rendered. Now, I'll have to admit that with a quick check into SpriteKit's API, I don't immediately see a way to do this. I do see such things being available in SceneKit... – Thorbjørn Lindeijer Jun 13 '15 at 20:50
  • 1
    @Krekin I'm not personally a developer of TilemapKit. I hope that they will consider making a free version available. – Thorbjørn Lindeijer Jun 13 '15 at 20:51
  • I'm the TilemapKit developer. 1) I'm afraid you can only use sprites for tiles in Sprite Kit if you want the map to be able to animate or replace tiles at runtime. 2) TilemapKit will draw only the visible tiles, and keeps only so many sprites in a pool as needed to fill the render area. 3) The real bottleneck on iOS is fillrate. 500 sprites using same texture is still 1 draw call, and that's most important. 1 sprite covering the area of the 500 sprite still draws the same amount of pixels which is probably 90% of the rendering time anyway. On OS X rendering performance is a non-issue. – CodeSmile Jun 14 '15 at 21:21
  • Thinking of it, it should be possible to render a tile layer onto a SKTexture and henceforth use that with a single sprite for a static layer. This could work, would add some preprocessing overhead though, and would only work if the resulting texture is compatible with the device's texture size limit (I think iOS 9 devices all support up to 4000x4000 textures). – CodeSmile Jun 14 '15 at 21:28
  • I tested on beta version of tilemapkit. My map is 32x32 and 320x50 in size and tilemap kit sucks the fps. I have observed somewhat Better performance with SKATK with the help of culling but on iphone 4s it still gives like 40 fps which shows little lag. Can Anyone suggest anything ? – Abhi Sep 10 '15 at 05:41