Skip to content

This Week in LesserPanda #6

Sean Bohan edited this page May 25, 2016 · 1 revision

Covering the week of 2016-05-19 to 2016-05-25.

This week I've been working on some project management work, and cleaned up the items on Trello. But also make some improvements to the engine itself, including support of object pool and Actor creating without a Scene.

Changes to Actor

Actor can only be initialised by calling spawnActor method of a Scene, which is not always a good idea. You won't be able to create instances and keep their reference for using later, simply because the instances can only be created by inserting a scene, which is quite weird.

So I modified the Scene.spawnActor and Scene.addActor methods, to be able to add manually created Actor instances to a scene whenever you want.

This also opens the possibility of pooling Actor instances.

Object Pool

Because of JavaScript GC system, you're free to create objects and forget. The VM will automatically collect unused objects and gives you better dream than those C++ programmers.

It is perfect and natural when our app can be slightly lag sometimes, and users won't complain. But we're living by creating games that run pretty fast and players always want more from you. Smooth is the key to rescue bad temper.

How can we prevent lags caused by GC? The answer is simple, just reuse the objects again and again.

A new utility function is added to engine/utils module to help make any class able to be pooled and reused. Let me show you how to do that:

import poolable from 'engine/utils';

class Bullet extends Actor {
  constructor() {
    super();
    // Create sprite, body and any object that always exist in an
    // instance of Bullet.
  }
  init(settings) {
    // This method will be called when an instance is requested.
    // Setup this object based on runtime settings passed in.
    //
    // You may need to reset body velocity, sprite scale...
  }
}

// Add object pool support, also you can provide a pre-allocating amount
// which is optional (default is 20).
poolable(Bullet, 30);

Now you can have better dreams again \O/

What's Next

Since no new features are planned for next release, I am going to focus on solving issues, and hope to make LesserPanda stable enough for any production use.