Phaser API Documentation

enable(gameObject, [hitArea], [hitAreaCallback], [dropZone])


Enable a Game Object for interaction.

If the Game Object already has an Interactive Object component, it is enabled and returned.

Otherwise, a new Interactive Object component is created and assigned to the Game Object's input property.

Input works by using hit areas, these are nearly always geometric shapes, such as rectangles or circles, that act as the hit area for the Game Object. However, you can provide your own hit area shape and callback, should you wish to handle some more advanced input detection.

If no arguments are provided it will try and create a rectangle hit area based on the texture frame the Game Object is using. If this isn't a texture-bound object, such as a Graphics or BitmapText object, this will fail, and you'll need to provide a specific shape for it to use.

You can also provide an Input Configuration Object as the only argument to this method.


name type arguments Default description
gameObject Phaser.GameObjects.GameObject

The Game Object to be enabled for input.

hitArea any | Phaser.Types.Input.InputConfiguration <optional>

Either an input configuration object, or a geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used.

hitAreaCallback Phaser.Types.Input.HitAreaCallback <optional>

The 'contains' function to invoke to check if the pointer is within the hit area.

dropZone boolean <optional> false

Is this Game Object a drop zone or not?


This Input Plugin.

Since: 3.0.0
Source: src/input/InputPlugin.js (Line 844)