Jump to content

Performance Improvement: Dealing with high-count swarm/horde based sprites.


mekotam
 Share

Recommended Posts

 I'm new to Phaser but familiar with Javascript. I'm working on my first game and am running into some (expected) performance issues.

 

The game is a basic kill 1 and 2 more spawn with a max number of enemies per level. Levels are calculated automatically by adding/multiplying the initial default settings such as Max number of Enemies, Enemy Fire Rate and Enemy Speed. As you can imagine, the higher the levels get the more enemies spawn. Currently it's causing some major performance issues around levels 20+ (lower on less equipped machines).

 

My question: Is there a better way to optimize this -or-  is there a more efficient way of handling these enemies?

 

I'm not sure what chunk(s) of code to include but I've linked the game at its current state below and can supply any code chunks needed for review.

 

http://dev.csds.co/pbshooter/

 

to skip to a certain level change the number in the url (level=#)

http://dev.csds.co/pbshooter/?level=20

 

Any help on this would be greatly appreciated!

Thanks in advance!




			
		
Link to comment
Share on other sites

Been up to level 50 without loosing noticeable performance. Pretty nice game by the way!

 

You have to keep realistic, even with super-good optimisations you won't be able to reach a thousand sprites all firing without loosing FPS. And I wonder if it's a good gameplay idea anyways, because it's just impossible to win! (player might loose the game way before, even for the best).

 

Did you try any kind of inspector? Chrome canvas inspector, Phaser debug plugin etc. ?

Link to comment
Share on other sites

1. Use a spritebatch for your stard field, enemies and bullets.

2. For your high levels recycle your enemies (ex : let's say that the player has to defeat 2k enemies to get to the next level, keep max 100 enemies on the screen and recycle them after they die so the player has the feeling that they are spawning). 

3. Try to stay away from emitters( I saw that you use them in your collision callbacks, that is very expensive).

4. I don't think you need the arcade physics system to be turned on since you are using basic collision detection and velocity( you could code these in the update loop which would be cheaper).

Link to comment
Share on other sites

I think your levels are being based off the update function (higher level, higher refresh faster timer = more lag), which shouldn't be the case. (for example http://dev.csds.co/pbshooter/?level=2555) it seems like your game AI loop is being based around a timer based on the LEVEL, not the global fixed Phaser update loop.

 

You shouldn't be increasing the global update loop, but the physic integers instead. (Velocity, movement, etc)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...