Thesaurus03
Thesaurus03

Reputation: 71

How can I improve FPS?

So I am having problem with game lag at the beginning of my project. So as soon as you tap to start the game it starts running on about 42-48 FPS, as you go on the game, it starts settling and ends up on about 58-59 FPS which is good. So I have been trying to fix it, I already tried by pre loading my texture atlases but it is still not working. So I ran the time profiler and it appears this is my problem:

It seems to be its my Update method. What I believe the problem is, it has to be with my Plist file. I am loading all my objects from one really long file. I tried running the project on a much shorter file and it runs perfectly at 60 FPS. Is there any way in which I can solve this?

Upvotes: 1

Views: 1006

Answers (3)

Epic Byte
Epic Byte

Reputation: 33968

So I am using the time profiler to see what is is that is making my FPS to drop down at the beginning and I believe according to it is this piece of code in my Update method:

Always be careful with the update method. Looping through and processing many nodes every frame can create overhead (and in the code you posted you are enumerating twice!).

Try adding a counter and run the code you posted less often and see how that impacts your FPS. For example, you could choose to run the code every 0.1 seconds instead of every 1/60 seconds.

In general you should try to avoid running code at the frame rate if you don't need to. For example, your game could run at 60 frames a second but you could have some game logic that runs every 0.1 as long as the gameplay is not affected. These are important optimizations to look for when designing a game.


Reading more into your description it looks like your problem might also be related to not preloading your assets correctly. Make sure you keep a single reference to your SKTextures, Fonts, Sounds, Actions and load them into memory before starting the game.

Upvotes: 0

sangony
sangony

Reputation: 11696

There are a couple of things which cause an initial drop in FPS. Before game play starts:

  1. Preload textures and texture atlases.
  2. Preload any sounds you are using.
  3. Preload any additional resources (plist, building maps, etc...)

In general you should always preload all assets before allowing game play to start.

Upvotes: 2

Schemetrical
Schemetrical

Reputation: 5536

You should probably use different sections for each pattern in the game.

In Mega Jump, different patterns are randomly loaded dynamically. This means, you can have different plists for different patterns, and as you go up, you can dealloc offscreen content and alloc new parts of the game from a random plist.

Always load things dynamically (possibly async) so that you never waste memory loading offscreen content that won't be used until later on.

Upvotes: 0

Related Questions