As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

54,364

Views

Beginner

Level

13

Comments

Optimizing Actor Performance

by Jon (Updated on 2015-10-17)


Introduction

One of the most important ways to ensure fast, smooth game performance is by making sure you're using actors in your game efficiently. The following tips can help you do this.

Don't create too many actors. Use Images instead.

Stencyl is based on Box2D, an industry standard physics engine that provides convincing collision detection out of the box. The numerous calculations required to run it can be taxing, so it's best to use fewer actors rather than more. There's no hard number which is "bad" since this can vary widely depending on the device and the game.

If you must have many objects on-screen, consider using Images in place of full actors.

Images are quasi-actors that do not make use of the physics engine - this improves performance if you don't need them to register collisions. Examples of such actors include decorations and special effects.

Remove Actors when they're no longer needed

There are many times when you should remove an actor from your game because they are temporary in nature. Examples include bullets, temporary power ups, certain enemies, and more.

Generally speaking, if an actor is only encountered once by the player, it should be removed as soon as possible. The conditions for removal will differ from game to game.

The following examples demonstrate a few common scenarios and pitfalls to watch out for.

Actor collides with another actor


Remove an actor

Warning: If actor A collides with actor B, there are no guarantees about which collision event runs first (since two will be dispatched - one for actor A and one for actor B). Do not make assumptions about which one will run first.

Actor leaves the screen


Leaving Screen

Explanation: In this case, the boolean attribute called Actor On Screen? ensures that the actor isn't removed before it has a chance to appear on screen. You'd set Actor On Screen? to true once that actor appears on screen. Then, when the actor leaves the screen again, it will be killed.

Now it's your turn. Share your tips.

What have you found, in your experiences, boosts performance of your games when you're in a bind? Use the comments area below to share your stories.

Print Article Edit Article How to Edit an Article
Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

13 Comments

Chris24XD 2
Can you <<recycled acotr>> with Custom Block?

0 4 years, 5 months ago
Jon
Yes, recycled actors are removed as a block and now happen by default when you "kill" an actor.
1 8 years, 12 months ago
rocketree
Is 'recycled actor' removed from stencyl 3.1? I can't find the block.
1 9 years, 10 months ago
SimenZhor
What exactly happens when an actor is killed? In 3.0 it seems that the recycle actor option is gone, but after a while of killing and creating actors (basically the only functionality of my game) I experience very slow framerate.
0 10 years, 7 months ago
HidetoKoudanshi
There's a typo (return pressed oddly) in your text:
___________________________________ __
In the examples above, we chose to create a recycled actor for bullets and explosions, the types of actors we would want to exist on screen temporarily and potentially have a lot of. F

or the menu button...
----------------------------------- ---------

Reconnect the two lines back into its proper paragraph.

1 10 years, 7 months ago
Jon
Dincicode: Excessive animation switching can impair performance because it allocates a new physics body. Looping doesn't make a difference either way.
0 10 years, 8 months ago
Dincicode
Does switching animations from 100 milliseconds to 200 milliseconds for actors improve performance, and what about looping animations does that make a difference if the actors only have 1 frame??
1 11 years, 6 months ago
Silux
I found a cause of lag also having many layers of trasparent backgrounds/foregrounds, to create an actor that collides upon another, bigger than screen and always simulating actors, creating more than 12 recycled actors at once(included point at and set velocity), to create trasparent actors.
0 12 years, 7 months ago
bigdaddio
GC is not all that great, no matter what anyone says. I have also created XBLIG and the GC will often take more than a frame to complete causing a frame to drop. Do this often enough and you get a stuttering mess that since we do not have very deep debuggers would be difficult to find.

0 13 years, 1 month ago
SpaghettiToastBook
One of the pictures has a create actor block in the "when drawing" wrapper.
2 13 years, 1 month ago

Sign In to Comment