5

My project runs at 55-60FPS on an iPhone 6 but anything older is completely unplayable because something is eating CPU.

I think the issue is related to the number of tiles and layers on my map (64x256 with 4 layers) and Instruments shows "SKCRenderer:preprocessSpriteImp(..." taking 5198ms (23.2%) running time.

Does JSTileMap load every single tile's image (visible or not) at once? This post from RW indicates that is the case and that it could be worked around for large performance boosts: http://www.raywenderlich.com/forums/viewtopic.php?f=29&t=9479

In another performance note - Sprite Kit checks all it's nodes and decides which ones it needs to display each frame. If you have a big tile map, this can be a big performance hit. JSTileMap loads all the nodes (SKSpriteNode for each tile) when it loads the tile map. So, I was also seeing performance issues in the Sprite Kit version with my maps (which are 500 x 40 tiles). I added a check to my version of JSTileMap that's included in the kit that marks the hidden property of each tile, then intelligently unhides and hides only the tiles that enter/exit the screen space. That increased performance on these larger maps significantly.

Unfortunately that post does not go into detail regarding the steps taken to remedy this.

My first thought was to (I'm a beginner, please be gentle) create an array of nodes by looping through each point and checking for a tile on the specific layer. From there I'd work on adding/removing them based on distance from the player.

This didn't work, because the process of adding nodes to an array simply caused the app to hang forever on larger maps.

Could someone lend a hand? I'd love to work with larger/more complicated tilemaps but this performance issue is destroying my brain.

Thanks for reading!

UPDATE: Big thanks to SKAToolKit: https://github.com/SpriteKitAlliance/SKAToolKit

Their culling feature solved my problem and I'm now running even larger maps at less than 35% CPU.

Norm
  • 53
  • 4
  • 1
    Our SKA group has been working on a took kit for loading Tiled Maps. You may want to give it a try and see if you see any performance changes. https://github.com/SpriteKitAlliance/SKAToolKit I would be very interested in you have the same issue or not. I have put a lot of work into optimizing it for performance. If you don't get the desired performance I could add the functionality mentioned above I would just need a sample map that would cause the slowdown you are seeing. – Skyler Lauren Jun 10 '15 at 11:48
  • Thanks Skyler! I'll dig into this tonight and let you know how it works. – Norm Jun 10 '15 at 12:24
  • @SkylerLauren I'm sorry for these terrible newbie questions but I have a few: 1) Will I require a bridging header to make use of this kit in a Swift project, similar to JSTileMap? and 2) Must I pack textures in a special way to work with JSON maps? I'm using TexturePacker and had previously been creating atlases in their Swift template, which worked fine with TMX maps. I see your example project has a TMX file and JSON exported file, and the images didn't appear to be in the same atlas format. Thank you so much! – Norm Jun 10 '15 at 12:43
  • @SkylerLauren one more question: "When creating your tiled map SKATiledMap will create physical bodies if it finds these properties on a tile or object. SKACollisionType : SKACollisionTypeRect" Does this mean I need to set custom properties in Tiled for physics before saving the map? – Norm Jun 10 '15 at 12:47
  • 1) yes we haven't made a Swift version yet and you will have to bridge it but that is on our list of to dos. 2)You shouldn't have to do anything special other than make sure the .png your map is using is in your app bundle. 3)No you don't have to use the auto generated physical bodies. That is just an added feature to make things easier. If you have more question feel free to email me at skyler@skymistdevelopment.com =) – Skyler Lauren Jun 10 '15 at 14:10
  • Thank you very much, I hope I'm able to contribute to some of your projects when I finally become proficient. I've always been a big fan of tile based games so working in this space is like a dream come true. Have a great day! – Norm Jun 10 '15 at 14:15

1 Answers1

2

JSTileMap has some issues handling larger maps but you do have a couple of options to consider:

  1. Break your large map into several smaller pieces and load each new piece as required.
  2. Only load those objects which are in the player's vicinity.
  3. Only load those tiles which are in the player's vicinity.

I personally found it impossible to accomplish #3 with JSTileMap as I could not locate an array holding the map tiles. I solved this issue by using the SKAToolKit which provides easy access to map tile arrays. It is an excellent resource for parsing maps created in Tiled.

sangony
  • 11,636
  • 4
  • 39
  • 55
  • 1
    Sangony, thank you very much for this answer. I hadn't heard of SKAToolKit before today and this, combined with Skyler's recommendation, is going to have me working with it ASAP. P.S: As I'm learning to program I often find myself benefitting from answers you've posted on SA, you're a huge help! – Norm Jun 10 '15 at 12:25
  • @Norm - Thank you for the kind words :) – sangony Jun 10 '15 at 12:39