GameObject

The base GameObject component. It can be used to create a component for your own Phaser game object.

Child components are able to use useGameObject() to get the instance.

Props

NameTypeDefaultDescription
create*
(scene: Scene) => Instance

Called when it’s time to instantiate the game object. You can return any Phaser GameObject instance.

active
boolean

Assigns the active property to the instance. Setting this to false will prevent onUpdate etc. props from running.

See: https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.GameObject.html#active__anchor

applyProps
Partial<{ [PropKey in keyof Partial]: ApplyProp, Partial[PropKey]>; }>

When extra props are passed on to GameObject, they are assigned to the instance and updated with an effect. i.e, a prop of x=&#123;1} would convert to instance.x = 1. applyProps lets you customize how each extra prop is applied by providing the key of the prop and a function to run.

This does not have to provide a method for each prop provided. If a key does not exist for the prop, it will fallback to assigning the prop to the instance.

Example:

applyProps=&#123;&#123;
 text: (instance, value) => instance.setText(value),
 style: (instance, value) => instance.setStyle(value)
}}
destroy
(instance: Instance, scene: Scene) => void

Called when the component unmounts and the instance needs to be destroyed. By default, it calls the GameObject’s destroy method

interactive
boolean InputConfiguration

Enables input events on the GameObject. Phaser will use the texture to determine the hit area. If this GameObject does not have a texture then you will need to manually set the hit area by passing in an object

name
string

Assigns a name to the instance. This can helpful when you need to find other instances by name.

See: https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.GameObject.html#name__anchor

onCreate
(self: Instance) => void

Called after object is created and added to the scene

onDrag
(self: Instance, pointer: Pointer, dragX: number, dragY: number) => void

 

onDragEnd
(self: Instance, pointer: Pointer, dragX: number, dragY: number) => void

 

onDragEnter
(self: Instance, pointer: Pointer, target: GameObject) => void

 

onDragLeave
(self: Instance, pointer: Pointer, target: GameObject) => void

 

onDragOver
(self: Instance, pointer: Pointer, target: GameObject) => void

 

onDragStart
(self: Instance, pointer: Pointer, dragX: number, dragY: number) => void

 

onDrop
(self: Instance, pointer: Pointer, target: GameObject) => void

 

onPointerDown
(self: Instance, pointer: Pointer, localX: number, localY: number, event: EventData) => void

 

onPointerMove
(self: Instance, pointer: Pointer, localX: number, localY: number, event: EventData) => void

 

onPointerOut
(self: Instance, pointer: Pointer, event: EventData) => void

 

onPointerOver
(self: Instance, pointer: Pointer, localX: number, localY: number, event: EventData) => void

 

onPointerUp
(self: Instance, pointer: Pointer, localX: number, localY: number, event: EventData) => void

 

onPointerWheel
(self: Instance, pointer: Pointer, deltaX: number, deltaY: number, deltaZ: number, event: EventData) => void

 

onPostUpdate
(self: Instance, time: number, delta: number) => void

Called during the scene’s postupdate loop

onPreUpdate
(self: Instance, time: number, delta: number) => void

Called during the scene’s preupdate loop

onUpdate
(self: Instance, time: number, delta: number) => void

Called during the scene’s update loop

ref
RefFunction GameObject