Phaser API Documentation

  Version: 
registerGameObject(key, [factoryCallback], [creatorCallback])

Description:

Registers a new type of Game Object with the global Game Object Factory and / or Creator. This is usually called from within your Plugin code and is a helpful short-cut for creating new Game Objects.

The key is the property that will be injected into the factories and used to create the Game Object. For example:

this.plugins.registerGameObject('clown', clownFactoryCallback, clownCreatorCallback);
// later in your game code:
this.add.clown();
this.make.clown();

The callbacks are what are called when the factories try to create a Game Object matching the given key. It's important to understand that the callbacks are invoked within the context of the GameObjectFactory. In this context there are several properties available to use:

this.scene - A reference to the Scene that owns the GameObjectFactory. this.displayList - A reference to the Display List the Scene owns. this.updateList - A reference to the Update List the Scene owns.

See the GameObjectFactory and GameObjectCreator classes for more details. Any public property or method listed is available from your callbacks under this.

Parameters:

name type arguments description
key string

The key of the Game Object that the given callbacks will create, i.e. image, sprite.

factoryCallback function <optional>

The callback to invoke when the Game Object Factory is called.

creatorCallback function <optional>

The callback to invoke when the Game Object Creator is called.

Since: 3.8.0