Extends

Public Properties

alive : boolean

This is set automatically by the Health components damage method should the object run out of health.
Or you can toggle it via your game code.

This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates.
However you can use Group.getFirstAlive in conjunction with this property for fast object pooling and recycling.

alpha : number

anchor :Point

The anchor sets the origin point of the texture.
The default is 0,0 this means the texture's origin is the top left
Setting than anchor to 0.5,0.5 means the textures origin is centered
Setting the anchor to 1,1 would mean the textures origin points will be the bottom right corner

autoCull : boolean

A Game Object with autoCull set to true will check its bounds against the World Camera every frame.
If it is not intersecting the Camera bounds at any point then it has its renderable property set to false.
This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely.

This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
or you have tested performance and find it acceptable.

[readonly] bottom : number

cacheAsBitmap : boolean

Set if this display object is cached as a bitmap.
This basically takes a snap shot of the display object as it is at that moment. It can provide a performance benefit for complex static displayObjects.
To remove simply set this property to 'null'

exists : boolean

Controls if this Game Object is processed by the core game loop.
If this Game Object has a physics body it also controls if its physics body is updated or not.
When exists is set to false it will remove its physics body from the physics world if it has one.
It also toggles the visible property to false as well.

Setting exists to true will add its physics body back in to the physics world, if it has one.
It will also set the visible property to true.

Type

fixedToCamera : boolean

A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.

The values are adjusted at the rendering stage, overriding the Game Objects actual world position.

The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world
the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times
regardless where in the world the camera is.

The offsets are stored in the cameraOffset property.

Note that the cameraOffset values are in addition to any parent of this Game Object on the display list.

Be careful not to set fixedToCamera on Game Objects which are in Groups that already have fixedToCamera enabled on them.

freezeFrames : boolean

[readonly] fresh : boolean

A Game Object is considered fresh if it has just been created or reset and is yet to receive a renderer transform update.
This property is mostly used internally by the physics systems, but is exposed for the use of plugins.

height : number

hitArea :Rectangle | Circle | Ellipse | Polygon

This is the defined area that will pick up mouse / touch events. It is null by default.
Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)

Type

inputEnabled : boolean

By default a Game Object won't process any input events. By setting inputEnabled to true a Phaser.InputHandler is created
for this Game Object and it will then start to process click / touch events and more.

The key of the image or texture used by this Game Object during rendering.
If it is a string it's the string used to retrieve the texture from the Phaser Image Cache.
It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
If a Game Object is created without a key it is automatically assigned the key __default which is a 32x32 transparent PNG stored within the Cache.
If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key __missing which is a 32x32 PNG of a green box with a line through it.

Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it.
In PIXI a regular mask must be a PIXI.Graphics object. This allows for much faster masking in canvas as it utilises shape clipping.
To remove a mask, set this property to null.

pendingDestroy : boolean

A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update.
You can set it directly to allow you to flag an object to be destroyed on its next update.

This is extremely useful if you wish to destroy an object from within one of its own callbacks
such as with Buttons or other Input events.

[readonly] top : number

transformCallback : Function

The transform callback is an optional callback that if set will be called at the end of the updateTransform method and sent two parameters:
This Display Objects worldTransform matrix and its parents transform matrix. Both are PIXI.Matrix object types.
The matrix are passed by reference and can be modified directly without needing to return them.
This ability allows you to check any of the matrix values and perform actions such as clamping scale or limiting rotation, regardless of the parent transforms.

width : number

The world coordinates of this Game Object in pixels.
Depending on where in the display list this Game Object is placed this value can differ from position,
which contains the x/y coordinates relative to the Game Objects parent.

clearFrames()

crop(rect, copy)

Crop allows you to crop the texture being used to display this Game Object.
Setting a crop rectangle modifies the core texture frame. The Game Object width and height properties will be adjusted accordingly.

Cropping takes place from the top-left and can be modified in real-time either by providing an updated rectangle object to this method,
or by modifying cropRect property directly and then calling updateCrop.

The rectangle object given to this method can be either a Phaser.Rectangle or any other object
so long as it has public x, y, width, height, right and bottom properties.

A reference to the rectangle is stored in cropRect unless the copy parameter is true,
in which case the values are duplicated to a local object.

Useful function that returns a texture of the displayObject object that can then be used to create sprites
This can be quite useful if your displayObject is static / complicated and needs to be reused multiple times.

Parameters

Name

Type

Description

resolution

Number

The resolution of the texture being generated

scaleMode

Number

See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values

Parameters

This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.

frame

string
|
number

<optional>

If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.

stopAnimation

boolean

<optional>

true

If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing.

overlap(displayObject) → {boolean}

Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object,
which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a getBounds method and result.

This check ignores the hitArea property if set and runs a getBounds comparison on both objects to determine the result.

Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency.
It should be fine for low-volume testing where physics isn't required.

Sets the sounds to be played whenever this Button is interacted with. Sounds can be either full Sound objects, or markers pointing to a section of a Sound object.
The most common forms of sounds are 'hover' effects and 'click' effects, which is why the order of the parameters is overSound then downSound.

Call this function with no parameters to reset all sounds on this Button.

Returns

update()

Override this method in your own custom objects to handle any update requirements.
It is called immediately after preUpdate and before postUpdate.
Remember if this Game Object has any children you should call update on those too.