Extends

Members

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.

Type:

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.

body is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated
properties and methods via it.

By default Game Objects won't add themselves to any physics system and their body property will be null.

To enable this Game Object for physics you need to call game.physics.enable(object, system) where object is this object
and system is the Physics system you are using. If none is given it defaults to Phaser.Physics.Arcade.

You can alternatively call game.physics.arcade.enable(object), or add this Game Object to a physics enabled Group.

Important: Enabling a Game Object for P2 or Ninja physics will automatically set its anchor property to 0.5,
so the physics body is centered on the Game Object.

If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics.

bottom : number

Type:

cacheAsBitmap : boolean

Sets if this DisplayObject should be cached as a bitmap.

When invoked it will take a snapshot of the DisplayObject, as it is at that moment, and store it
in a RenderTexture. This is then used whenever this DisplayObject is rendered. It can provide a
performance benefit for complex, but static, DisplayObjects. I.e. those with lots of children.

Cached Bitmaps do not track their parents. If you update a property of this DisplayObject, it will not
re-generate the cached bitmap automatically. To do that you need to call DisplayObject.updateCache.

To remove a cached bitmap, set this property to null. Cache this DisplayObject as a Bitmap. Set to null to remove an existing cached bitmap.

Type:

data : Object

An empty Object that belongs to this Game Object.
This value isn't ever used internally by Phaser, but may be used by your own code, or
by Phaser Plugins, to store data that needs to be associated with the Game Object,
without polluting the Game Object directly.

filterArea : Rectangle

Type:

filters : Array

Sets the filters for this DisplayObject. This is a WebGL only feature, and is ignored by the Canvas
Renderer. A filter is a shader applied to this DisplayObject. You can modify the placement of the filter
using DisplayObject.filterArea.

To remove filters, set this property to null.

Note: You cannot have a filter set, and a MULTIPLY Blend Mode active, at the same time. Setting a
filter will reset this DisplayObjects blend mode to NORMAL. An Array of Phaser.Filter objects, or objects that extend them.

Type:

fixedToCamera : boolean

A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets
are stored in the cameraOffset property, which is initialized with the current object coordinates.

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.

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.

Type:

<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.

Type:

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.

If you set this property to false it will stop the Input Handler from processing any more input events.

If you want to temporarily disable input for a Game Object, then it's better to set
input.enabled = false, as it won't reset any of the Input Handlers internal properties.
You can then toggle this back on as needed.

Type:

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.

Type:

Sets a mask for this DisplayObject. A mask is an instance of a Graphics object.
When applied it limits the visible area of this DisplayObject to the shape of the mask.
Under a Canvas renderer it uses shape clipping. Under a WebGL renderer it uses a Stencil Buffer.
To remove a mask, set this property to null. The mask applied to this DisplayObject. Set to null to remove an existing mask.

Type:

The parent DisplayObjectContainer that this DisplayObject is a child of.
All DisplayObjects must belong to a parent in order to be rendered.
The root parent is the Stage object. This property is set automatically when the
DisplayObject is added to, or removed from, a DisplayObjectContainer.

Type:

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.

Type:

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.

Type:

<readonly> worldAlpha : number

The multiplied alpha value of this DisplayObject. A value of 1 is fully opaque. A value of 0 is transparent.
This value is the calculated total, based on the alpha values of all parents of this DisplayObjects
in the display list.

To obtain, and set, the local alpha value, see the alpha property.

Note: This property is only updated at the end of the updateTransform call, once per render. Until
that happens this property will contain values based on the previous frame. Be mindful of this if
accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.

Type:

<readonly> worldPosition : PIXI.Point

The coordinates, in pixels, of this DisplayObject within the world.

This property contains the calculated total, based on the positions of all parents of this
DisplayObject in the display list.

Note: This property is only updated at the end of the updateTransform call, once per render. Until
that happens this property will contain values based on the previous frame. Be mindful of this if
accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.

Type:

<readonly> worldRotation : number

The rotation, in radians, of this DisplayObject.

This property contains the calculated total, based on the rotations of all parents of this
DisplayObject in the display list.

Note: This property is only updated at the end of the updateTransform call, once per render. Until
that happens this property will contain values based on the previous frame. Be mindful of this if
accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.

Type:

<readonly> worldScale : PIXI.Point

The global scale of this DisplayObject.

This property contains the calculated total, based on the scales of all parents of this
DisplayObject in the display list.

Note: This property is only updated at the end of the updateTransform call, once per render. Until
that happens this property will contain values based on the previous frame. Be mindful of this if
accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.

Type:

This property contains the calculated total, based on the transforms of all parents of this
DisplayObject in the display list.

Note: This property is only updated at the end of the updateTransform call, once per render. Until
that happens this property will contain values based on the previous frame. Be mindful of this if
accessing this property outside of the normal game flow, i.e. from an asynchronous event callback.

Type:

<readonly> z : number

The z depth of this Game Object within its parent Group.
No two objects in a Group can have the same z value.
This value is adjusted automatically whenever the Group hierarchy changes.
If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop.

Returns:

alignIn(container [, position] [, offsetX] [, offsetY])

Aligns this Game Object within another Game Object, or Rectangle, known as the
'container', to one of 9 possible positions.

The container must be a Game Object, or Phaser.Rectangle object. This can include properties
such as World.bounds or Camera.view, for aligning Game Objects within the world
and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
TileSprites or Buttons.

Please note that aligning a Sprite to another Game Object does not make it a child of
the container. It simply modifies its position coordinates so it aligns with it.

The Game Objects are placed in such a way that their bounds align with the
container, taking into consideration rotation, scale and the anchor property.
This allows you to neatly align Game Objects, irrespective of their position value.

The optional offsetX and offsetY arguments allow you to apply extra spacing to the final
aligned position of the Game Object. For example:

sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)

Would align the sprite to the bottom-right, but moved 20 pixels in from the corner.
Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place.
So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive
one expands it.

Returns:

alignTo(parent [, position] [, offsetX] [, offsetY])

Aligns this Game Object to the side of another Game Object, or Rectangle, known as the
'parent', in one of 11 possible positions.

The parent must be a Game Object, or Phaser.Rectangle object. This can include properties
such as World.bounds or Camera.view, for aligning Game Objects within the world
and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
TileSprites or Buttons.

Please note that aligning a Sprite to another Game Object does not make it a child of
the parent. It simply modifies its position coordinates so it aligns with it.

The Game Objects are placed in such a way that their bounds align with the
parent, taking into consideration rotation, scale and the anchor property.
This allows you to neatly align Game Objects, irrespective of their position value.

The optional offsetX and offsetY arguments allow you to apply extra spacing to the final
aligned position of the Game Object. For example:

sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)

Would align the sprite to the bottom-right, but moved 20 pixels in from the corner.
Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place.
So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive
one expands it.

Parameters:

Returns:

Type

boolean

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.

generateTexture( [resolution] [, scaleMode], renderer)

Generates a RenderTexture based on this DisplayObject, which can they be used to texture other Sprites.
This can be useful if your DisplayObject is static, or complicated, and needs to be reused multiple times.

Please note that no garbage collection takes place on old textures. It is up to you to destroy old textures,
and references to them, so they don't linger in memory.

Parameters:

Name

Type

Argument

Default

Description

resolution

number

<optional>

1

The resolution of the texture being generated.

scaleMode

number

<optional>

PIXI.scaleModes.DEFAULT

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

Returns:

getBounds(matrix)

Returns the bounds of the Sprite as a rectangle.
The bounds calculation takes the worldTransform into account.

The worldTransform was calculated during the last render pass and is not updated when you call this method.
If this Sprite was just created and has never been rendered, you can call updateTransform on the Sprite itself.
If any of the Sprite's ancestors have been positioned, scaled, or rotated since the last render pass,
those changes have not yet have been applied to this Sprite's worldTransform. Call updateTransform
on the root-most (highest) ancestor that was changed.

loadTexture(key [, frame] [, stopAnimation])

Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache.

If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the frame or frameName properties instead.

You should only use loadTexture if you want to replace the base texture entirely.

Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU.

You can use the new const Phaser.PENDING_ATLAS as the texture key for any sprite.
Doing this then sets the key to be the frame argument (the frame is set to zero).

This allows you to create sprites using load.image during development, and then change them
to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS'
and swapping it to be the key of the atlas data.

Note: You cannot use a RenderTexture as a texture for a TileSprite.

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.

Returns:

overlap(displayObject)

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.

Returns:

setScaleMinMax(minX, minY, maxX, maxY)

Sets the scaleMin and scaleMax values. These values are used to limit how far this Game Object will scale based on its parent.

For example if this Game Object has a minScale value of 1 and its parent has a scale value of 0.5, the 0.5 will be ignored
and the scale value of 1 will be used, as the parents scale is lower than the minimum scale this Game Object should adhere to.

By setting these values you can carefully control how Game Objects deal with responsive scaling.

If only one parameter is given then that value will be used for both scaleMin and scaleMax:
setScaleMinMax(1) = scaleMin.x, scaleMin.y, scaleMax.x and scaleMax.y all = 1

If only two parameters are given the first is set as scaleMin.x and y and the second as scaleMax.x and y:
setScaleMinMax(0.5, 2) = scaleMin.x and y = 0.5 and scaleMax.x and y = 2

If you wish to set scaleMin with different values for x and y then either modify Game Object.scaleMin directly,
or pass null for the maxX and maxY parameters.

Call setScaleMinMax(null) to clear all previously set values.

Parameters:

Name

Type

Description

minX

number
|
null

The minimum horizontal scale value this Game Object can scale down to.