melonJS
    Preparing search index...

    Function register

    • Register an object to the pool.
      Pooling must be set to true if more than one such objects will be created.
      (Note: for an object to be poolable, it must implement an onResetEvent method)

      Registered classes are also automatically available as Tiled object factories, meaning objects placed in a Tiled map with a matching class or name will be instantiated using the registered constructor. For more control, use registerTiledObjectClass or registerTiledObjectFactory instead.

      Parameters

      • className: string

        as defined in the Name field of the Object Properties (in Tiled)

      • classObj: object

        corresponding Class to be instantiated

      • Optionalrecycling: boolean = false

        enables object recycling for the specified class

      Returns void

      // implement CherryEntity
      class Cherry extends Sprite {
      onResetEvent() {
      // reset object mutable properties
      this.lifeBar = 100;
      }
      };
      // add our users defined entities in the object pool and enable object recycling
      // this also registers "cherrysprite" as a Tiled object factory, so any object
      // with class or name "cherrysprite" in a Tiled map will create a Cherry instance
      me.pool.register("cherrysprite", Cherry, true);