Call: (209) 560-6611

AS3 Optimizing code for faster processing

Date: February 6, 2015 Author: ang Category: Tutorials Tags: , Comments: 0

Below are some methods that will allow your mobile apps and games to run faster. These tips assume you are using the Starling framework.I will add more to this list later.

  1. For mobile apps, use 'arrays classes' instead of 'vector classes'. 
  2. Use the 'Starling' framework.
  3. Use 'Feathers', a 'Starling' user interface component.
  4. Don't count the length of arrays every time in loop statements. Instead count the length once and store it in a variable to use in the loop.
  5. Instead of creating and destroy sprites rapidly in a game, like when firing bullets, use 'object pooling'.
  6. Avoid 'pixel perfect collision detection' at all costs. Use 'bounding box collision detection' or 'distance collision detection'/'sphere based collision detection' instead. Distance collision detection is more accurate than bounding box collision detection.
  7. Create variables(point class) that represent x and y coordinators as class properties instead of inside loops. Changing the x and y coordinates of an object on every frame takes up less memory than instantiating x and y coordinates on every frame. 
  8. Set the Starling blendMode = none on object that have no transparencies i.e. backgrounds.
  9. Reduce the number of times your update functions update on your collision detection classes. Usually collision detection is checked on every frame, but when your game is playing at 60 frames per second this is excessive.
  10. Set objects that don't use touch events to 'touchable = false;'.

Other helpful resources

Starling forums: http://forum.starling-framework.org

Lee Brimlow's tutorial site: http://gotoandlearn.com/

Hamanths Sharma's tutorial site: http://www.hsharma.com/tutorials/

Leave a Reply

Your email address will not be published. Required fields are marked *

Before you post, please prove you are sentient.

What is 8 * 8?

Before you post, please prove you are sentient.

What do bees make?