2

I'm experiencing some lag for the first time in developing a platformer game for iOS. I'm relatively new to development, so I'm assuming I'm already making mistakes that can slow my game down.

I just have a few questions that I'm confused about.

  1. I'm building a platformer so I will have nodes outside the scenes camera view at times. Should I be looping through all nodes and removing them from the scene if not? Would this help with performance, or does SpriteKit automatically do this with the skcameranode?

  2. I'm wanting to build sort of like an open world kind of feel, so some levels could be large. I have a lot of 128x128 tiles that I use with tilemapnodes for the foreground. The stuff like the ground, dirt, platforms, etc that the player will interact with. I also have 5 layers of parallax'ed backgrounds that are 512x512 tiles, each with their own tilemapnode. My question is about these huge levels. Should I be breaking up these tilemapnodes into sections? Would this help you performance?

  3. Last question, So the 128x128 tiles are really 256x256. I just scaled down the tilemapnode. I created a huge tilemapnode for the foreground and made the ground and floor and a few hills with this one map node. When I would move the player to an area that was dense with nodes, it would lag down to 45-55 fps. when away from this dense area, it would go back to 60 fps; leads me to believe that SpriteKit handles the question 1 thing. Anyways, rather than creating the images in 256x256 and scaling down when needed, will it help performance creating separate images in different sizes rather than using the scaling option? (I am using the 1,2,3x images for every image, if that matters)

Thanks for any help.

Discoveringmypath
  • 1,049
  • 9
  • 23
  • Probably can't diagnose anything without your code. Do you have a lot of stuff in `.update()` or any of the other "every-frame" methods? Usually things that affect performance are ShapeNodes, EffectNodes, and LightingNodes. SpriteNodes you can have thousands of on screen on any modern device and do well. Spritekit does manage off-screen nodes to a degree. – Fluidity Jun 10 '17 at 05:24
  • Are you using simulator? Or which device are you testing on? – Fluidity Jun 10 '17 at 05:24
  • iPhone 6+. I think the initial lag I was experiencing might be from the huge tilemapnode, that I scaled down. With out that, it runs fine. Just first time experiencing the lag, figured it was time to start researching best practices for performance... I don't have a lot in update... I'm more asked my for generalized answer rather than provide code of my example... – Discoveringmypath Jun 10 '17 at 05:29
  • well, it could be due to loading assets on the fly.. have you pre-loaded everything? – Fluidity Jun 10 '17 at 05:30
  • Everything is pre loaded and initialized in the didmove method. Do you have any feedback for the 3 questions? – Discoveringmypath Jun 10 '17 at 05:31
  • 1
    #3 is obviously yes to some degree, it will use less memory if you use smaller textures, and less CPU cycles to scale down images. I'm not sure that is your problem though. I haven't used tilemaps much, but it would be worth for #2 trying to split them up in a side project. #1 can be a problem too, especially if you have a LARGE world. Apple even tell syou to do that – Fluidity Jun 10 '17 at 05:35
  • 1
    read #3 and #4 here: https://code.tutsplus.com/tutorials/spritekit-from-scratch-advanced-techniques-and-optimizations--cms-26470 – Fluidity Jun 10 '17 at 05:37
  • 1
    another useful bit is to see how many calls to `draw()` you have.. In your GameViewController (or wherever) you want to do `view.showsDrawCount = true` then you can get an actual idea of how many more calls those populated areas are calling, and then if you override your methods in #3 of that article, you can measure the time in between each method to figure out where the issue is more exactly. – Fluidity Jun 10 '17 at 05:43
  • Thanks for the reference. For #1 I didn't know if this was handled automatically or not, so I'll take note of that. I've been making a few subtle changes to test out #2, I can try the side project though to quickly test that out. Thanks again for the info! – Discoveringmypath Jun 10 '17 at 05:43
  • 1
    here is another reference for best practices and performance by apple: https://youtu.be/ZIWVj6LMuSw?t=19m6s there are also some tidbits in the programming guide (stil llooking for that reference to #1 they said) – Fluidity Jun 10 '17 at 05:48
  • Thanks again, that article helps for sure... l – Discoveringmypath Jun 10 '17 at 05:54
  • 1
    I found an old version of the programming guide, look at the best practices section page 107.. it goes over #1 of yor question:http://upyun.cocimg.com/cocoachina/SpriteKit_PG.pdf – Fluidity Jun 10 '17 at 05:57
  • Thanks for that last reference, I saw reference to it, but all links were broken, I'll check that out – Discoveringmypath Jun 10 '17 at 06:00
  • yeah the apple links to it are broken for some reason .. – Fluidity Jun 10 '17 at 06:02

1 Answers1

2

Here are some general tips for performance, as mentioned in the comments:

Fluidity
  • 3,985
  • 1
  • 13
  • 34
  • That programming guide is a gem, thanks for the reference. Quick question about the didbegin contact method, do you know when in the loop that is called? Thanks for the help, Wiuld you he available for me to ask questions through email? – Discoveringmypath Jun 10 '17 at 13:19
  • 1
    @Discoveringmypath i cant remember right now. its somewhere in the physics simulation box. before didsimulate – Fluidity Jun 10 '17 at 18:33