While we’re constantly working to improve the performance of the Popfly Game Creator, there are a number of tweaks you can make to your games right now to improve your users’ frame rate.
Right now, there are two main bottlenecks for games created using Popfly and depending on the characteristics of your game, one or the other can probably help you.
Today we’ll talk about the biggest perf. hit for most games, which is collision detection between a large number of actors. There are a number of ways to address this.
The easiest trick is to make as many actors as possible non-solid:
This is a per state property, so if your actor has multiple states, make sure you set it for each one. When an actor is non-solid, it’s collision bounds will be drawn in blue instead of red.
When an actor is non-solid, it will no longer push or get pushed when it collides with other actors. This allows us to skip testing it for collisions except when there is a collision listener whose event includes the actor. Even then we only have to test it against other actors that are included as the other actor on the same event.
The next approach is to limit the number of actors you use on any scene. While this can lead to a less compelling game, but if your game is bottlenecked on collision checking, it is guaranteed to increase performance.
If neither of the above is desirable, you can also increase performance by limiting the motion of your actors. When an actor has not moved, it often allows us to skip testing it in parts of our collision detection. This also improves Silverlight drawing performance (which we’ll talk more about tomorrow) since we will not have to update the Silverlight plugin and Silverlight will not have to re-render the actor in its new position.
Finally, if you are spawning new actors throughout the course of your game (through shoot behaviors, Appear behaviors, effects etc) there are a couple of things you can do to keep things snappy.
First, make sure you limit the lifetime of the spawned actors. Leaving the “disappear on scene leave” behaviors intact helps with this since once the actor reaches the edge of the screen, the actor will be removed from the game keeping the total number of actors low. Second, limit the rate at which new actors are added. For example, if you allow the player to shoot, try limiting the rate of fire by setting a property to 1 on your actor when the player presses the fire button, then clear the property to 0 on a timer. Then simply add a filter to the fire behavior to only allow the player to fire when the property is 0. Alternately, you can limit the # of bullets the player can fire at once by filtering on the # of BulletName property (you may have to copy the value of this property locally to your actor from the scene using an “every frame” timer). Lastly, you can throttle down the rate at which your enemies fire when there are a lot of enemies on the screen through custom code or using a filter on # of EnemyBulletName.
Hopefully these tips will help those of you with games whose performance is bound by the total number of actors. Because naive collision detection’s performance is an O(N^2 ) problem (where N is the number of actors, adding one more actor will cause another N + 1 collision checks to take place), adding actors can quickly cause problems. Using the tips above can really improve performance. If you’re having trouble after following these tips or they aren’t helping, be sure to head to the forums where other users and members of the Popfly team can help.
Tomorrow I’ll follow up with Part 2 where I will provide some tips for creating actors that are easy for Silverlight to draw and also help keep Popfly’s game engine running fast. Stay tuned.