Username or E-mail
Password (Forgot?)
New? Sign Up
Join or Sign In
Forums Stencylpedia Stencyl TV Translations Go Pro - Plans & Pricing Download Stencyl


Switch to Book Layout

1: Getting Started

  • Getting Started
  • Crash Course
  • Crash Course 2
  • StencylForge

2: Building Logic

  • What is a Behavior?
  • Creating a Behavior
  • Attributes
  • Game Attributes
  • Attribute Types
  • Events
  • Our Behaviors

3: Actors

  • What are Actors?
  • Animations
  • Motion & Forces
  • Physics
  • Controls
  • Collisions & Groups
  • Killing vs. Recycling
  • Tweening
  • Effects
  • Chapter 3 Challenge

4: Scenes

  • Scene Basics
  • The Camera
  • Tilesets
  • Regions
  • Drawing Text & HUDs
  • Changing Scenes
  • Music, Sounds & Channels
  • Backgrounds
  • Customizing Actors
  • Chapter 4 Challenge

5: Game Mechanics

  • Saving
  • Pausing
  • 3rd Party Services
  • Web Requests

6: Advanced Topics

  • Get/Set Attributes
  • Custom Events
  • Blending Modes
  • Lists
  • Custom Blocks
  • Continuous Collisions

7: Testing & Tuning

  • Testing Games
  • Optimizing Performance 1
  • Optimizing Performance 2

8: The Last 10%

  • Flash Publishing
  • Standalone Apps
  • iOS App Store
  • Chrome Store
  • Making Money

M1: Mobile - Intro

  • Getting Started
  • Testing on your Device
  • Flash -> iOS Guide

M2: Mobile - Basics

  • Atlases
  • Drawing Text
  • Retina Display
  • Accelerometer
  • Joystick
  • Universal Games

M3: Mobile - Services

  • iAds
  • Game Center
  • In-App Purchases

M4: Mobile - Publishing

  • Debugging
  • Publishing to the App Store
  • Optimizing Performance
  • Promoting your Game

A: Troubleshooting

  • Showstoppers
  • General FAQ
  • iOS FAQ
  • The 90% Memory Warning
  • Recovering Broken Games
  • Can't Export to SWF
  • Reloading Documents
  • Generating Logs
  • Flash Security Settings
  • How to Report Bugs

B: How-To Guides

  • Importing Assets
  • Scene Designer
  • Code Mode
  • Font Editor
  • Pencyl (Image Editor)
  • Tile Editor (Shapes)
  • Game Cleaner

C: Reference

  • Glossary
  • Block Reference
  • Useful Shortcuts
  • Stencyl API

D: Resources

  • Stencyl TV
  • Abigayl's Guides
  • Giving Critiques
  • Creating Extensions
  • Translating Stencyl
  • Credits

3.0 Drafts (In Progress)

  • What's New in Stencyl 3.0?
  • Setup (Android)
  • Setup (Desktop)
  • Setup (iOS) - Concepts
  • Setup (iOS) - Mac
  • Setup (iOS) - Windows
  • Testing iOS on Windows
  • iOS Troubleshooter

  • Mobile App Scaling
  • Full Screen Mode
  • Simple Physics
  • Backgrounding an App

  • iOS App Store
  • Mac App Store
  • Windows Store
  • Google Play
  • HTML5

  • Android Ads
  • Android Purchases (WIP)
  • 4" Form Factor (iPhone 5)
  • Mobile Input
  • Mobile Features

  • Extending the Engine
  • iOS / Android Extensions
  • Developing the Official Extensions
  • Developing the Engine

  • iAds (Revised)
  • Game Center (Revised)
  • iOS Purchases (Revised)
  • Atlases (Revised)
  • Drawing Text (Revised)
  • Joystick (Revised)
  • Accelerometer (Revised)
  • Sounds (Revised, WIP)
  • Debugging (Revised, WIP)
  • iOS Performance (Revised)
Level: Beginner

Optimizing Actor Performance

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.

 

Contents

  • Recycle Actors when Possible
  • Avoid Excessive Actor Creation
  • Remove Actors when they're no longer needed

 

Recycle Actors When Possible

(Note: In Stencyl 3.0 and above, recycling is the only option available and is implicitly done when you create and kill an Actor.)

The game engine Stencyl uses has two types of actors, regular and one the engine can recycle. When the engine creates a regular actor, it introduces a new instance of a type of actor to a scene. The actor stays in the scene until removed. Regular actors are created using the Create Actor block.

Actors the engine can recycle work differently. With a recycled actor, Stencyl creates an actor and then adds it to a pool which exists outside the scene (i.e. a recycled actor in the pool exists in memory but is not visible in the scene in any way). An actor the engine can recycle is created with this block:

When the engine recycles an actor, using this block...

...the actor returns to the pool outside the scene. Once the actor is restored to its original state, it ends up in line to go back to the scene. It's returned when needed. Here's an illustration:

 

 

Avoid Creating Large Numbers of Actors Every Frame

If you place a create actor block into the Always event block, like this...

 

...Stencyl will attempt to create an actor every single frame, which at 60 frames per second, would mean 60 actors per second. This will obviously slow your game to a crawl.

 

Solution

Instead, put blocks that create actors into the When Created, When This Collides, or When This Hears blocks, or constrain actor creation using a conditional (if statement).

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, we'll only have one, and it will be permanent, so we don't need to create a version we can recycle - we can use the regular Create Actor block.

If this all sounds trivial and completely obvious, you might be surprised to see just how often we see this happen in the field. ;)

 

Remove Actors When Possible

There are many times when you should remove an actor from your game. Examples include bullets, special effects, temporary power ups, enemies, and more.

Any actor the player's actor doesn't need to run into more than once is an actor you should remove. An actor you want to remove (when certain conditions in your game are met) will need a Behavior that provides the logic for removal.

 

There are two ways to remove an actor, using the kill [actor] block...

...or the recycle [actor] block. Make sure you don't attempt to recycle a regular actor and vice versa.

 

A few good ways to remove actors are after a set time period, using the Do After block...

The logic in this Behavior is designed to prevent errors from occurring where the engine attempts to recycle an actor that's already been removed.

Other options include when an actor collides with another or when it leaves the screen.

In this case, the boolean attribute called Actor On Screen? is there to ensure the actor isn't removed before it has a chance to appear on screen. You would use logic elsewhere to set that boolean attribute to true once that actor appears on screen. Then, when the actor leaves the screen again, the logic shown above will remove it from the scene.

One other tip for removing temporary actors is to use logic in a Behavior that removes an actor under a range of conditions, e.g. leaving the screen and after a short period of time.

 

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.



Last Updated: 2013-01-29 by Jon

15456 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game, please ask a question on the forums. Thanks!
7 Comments
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 2 months, 2 days 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 1 year, 2 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 1 year, 8 months ago
SpaghettiToastBook
One of the pictures has a create actor block in the "when drawing" wrapper.
1 1 year, 8 months ago
Jon
The recycle functionality is not completely bug free. That's why it isn't the default yet.

Creating new actors on the fly is expensive in Box2D. We found substantial, very substantial performance improvements using recycled vs. not.

1 1 year, 10 months ago
Luxon5
Yes I also wonder about the difference between recycled and non-recycled actors. If recycled actors improve performance, why not use them all the time? Why would you ever have to avoid it and use a regular actor instead?
0 1 year, 10 months ago
herby
Why all that complication with the recycled actors? In my opinion it severely complicates design and can lead to bugs. Is garbage collecting not good enough to do its work (it does it anyway, for all the rest)?
-1 1 year, 11 months ago



Commenting Guidelines

Sign In to Comment

Make Games

  • What is Stencyl?
  • Roadmap
  • Pricing

Play

  • Arcade
  • Showcase

Community

  • Forums
  • Chat
  • Translations

Help

  • Stencylpedia
  • Stencyl TV

About Us

  • Blog
  • Contact Us
  • Press
  • Privacy
Follow Stencyl on Twitter



© 2013 Stencyl, LLC.