new Image(game, x, y, key, frame)
Parameters:
Name | Type | Description |
---|---|---|
game |
Phaser.Game | A reference to the currently running game. |
x |
number | The x coordinate of the Imaget. The coordinate is relative to any parent container this Image may be in. |
y |
number | The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in. |
key |
string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | The texture used by the Image during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture. |
frame |
string | number | If this Image 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. |
- Source:
Members
-
angle
-
Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90. If you wish to work in radians instead of degrees use the property Sprite.rotation instead. Working in radians is also a little faster as it doesn't have to convert the angle.
- Source:
Properties:
Name Type Description angle
number The angle of this Image in degrees.
-
autoCull
-
Should this Sprite be automatically culled if out of range of the camera? A culled sprite has its renderable property set to 'false'. Be advised this is quite an expensive operation, as it has to calculate the bounds of the object every frame, so only enable it if you really need it.
- Default Value:
- false
- Source:
Properties:
Name Type Description autoCull
boolean A flag indicating if the Sprite should be automatically camera culled or not.
-
<readonly> deltaX
-
Returns the delta x value. The difference between world.x now and in the previous step.
- Source:
Properties:
Name Type Description deltaX
number The delta value. Positive if the motion was to the right, negative if to the left.
-
<readonly> deltaY
-
Returns the delta y value. The difference between world.y now and in the previous step.
- Source:
Properties:
Name Type Description deltaY
number The delta value. Positive if the motion was downwards, negative if upwards.
-
<readonly> deltaZ
-
Returns the delta z value. The difference between rotation now and in the previous step.
- Source:
Properties:
Name Type Description deltaZ
number The delta value.
-
events
-
- Source:
Properties:
Name Type Description events
Phaser.Events The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
-
exists
-
- Default Value:
- true
- Source:
Properties:
Name Type Description exists
boolean If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
-
fixedToCamera
-
A Sprite that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. Note that if this Image is a child of a display object that has changed its position then the offset will be calculated from that.
- Default Value:
- false
- Source:
Properties:
Name Type Description fixedToCamera
boolean Fixes this Sprite to the Camera.
-
frame
-
- Source:
Properties:
Name Type Description frame
number Gets or sets the current frame index and updates the Texture for display.
-
frameName
-
- Source:
Properties:
Name Type Description frameName
string Gets or sets the current frame by name and updates the Texture for display.
-
game
-
- Source:
Properties:
Name Type Description game
Phaser.Game A reference to the currently running Game.
-
<readonly> inCamera
-
Checks if the Image bounds are within the game camera, otherwise false if fully outside of it.
- Source:
Properties:
Name Type Description inCamera
boolean True if the Image bounds is within the game camera, even if only partially. Otherwise false if fully outside of it.
-
input
-
- Source:
Properties:
Name Type Description input
Phaser.InputHandler | null The Input Handler for this object. Needs to be enabled with image.inputEnabled = true before you can use it.
-
inputEnabled
-
By default an Image won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is activated for this object and it will then start to process click/touch events and more.
- Source:
Properties:
Name Type Description inputEnabled
boolean Set to true to allow this object to receive input events.
-
<readonly> inWorld
-
Checks if the Image bounds are within the game world, otherwise false if fully outside of it.
- Source:
Properties:
Name Type Description inWorld
boolean True if the Image bounds is within the game world, even if only partially. Otherwise false if fully outside of it.
-
key
-
- Source:
Properties:
Name Type Description key
string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
-
name
-
- Source:
Properties:
Name Type Description name
string The user defined name given to this Sprite.
-
<readonly> renderOrderID
-
- Source:
Properties:
Name Type Description renderOrderID
number The render order ID, reset every frame.
-
<readonly> type
-
- Source:
Properties:
Name Type Description type
number The const type of this object.
-
world
-
- Source:
Properties:
Name Type Description world
Phaser.Point The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
Methods
-
bringToTop() → {Phaser.Image}
-
Brings the Sprite to the top of the display list it is a child of. Sprites that are members of a Phaser.Group are only bought to the top of that Group, not the entire display list.
- Source:
Returns:
This instance.
- Type
- Phaser.Image
-
crop(rect)
-
Crop allows you to crop the texture used to display this Image. Cropping takes place from the top-left of the Image and can be modified in real-time by providing an updated rectangle object.
Parameters:
Name Type Description rect
Phaser.Rectangle The Rectangle to crop the Image to. Pass null or no parameters to clear a previously set crop rectangle.
- Source:
-
destroy()
-
Destroys the Sprite. This removes it from its parent group, destroys the input, event and animation handlers if present and nulls its reference to game, freeing it up for garbage collection.
- Source:
-
kill() → {Phaser.Image}
-
Kills a Sprite. A killed Sprite has its alive, exists and visible properties all set to false. It will dispatch the onKilled event, you can listen to Sprite.events.onKilled for the signal. Note that killing a Sprite is a way for you to quickly recycle it in a Sprite pool, it doesn't free it up from memory. If you don't need this Sprite any more you should call Sprite.destroy instead.
- Source:
Returns:
This instance.
- Type
- Phaser.Image
-
loadTexture(key, frame)
-
Changes the Texture the Sprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache. This causes a WebGL texture update, so use sparingly or in low-intensity portions of your game.
Parameters:
Name Type Description key
string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
frame
string | number 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.
- Source:
-
postUpdate()
-
Internal function called by the World postUpdate cycle.
- Source:
-
preUpdate()
-
Automatically called by World.preUpdate.
- Source:
-
reset(x, y) → {Phaser.Image}
-
Resets the Sprite. This places the Sprite at the given x/y world coordinates and then sets alive, exists, visible and renderable all to true.
Parameters:
Name Type Description x
number The x coordinate (in world space) to position the Sprite at.
y
number The y coordinate (in world space) to position the Sprite at.
- Source:
Returns:
This instance.
- Type
- Phaser.Image
-
revive() → {Phaser.Image}
-
Brings a 'dead' Sprite back to life, optionally giving it the health value specified. A resurrected Sprite has its alive, exists and visible properties all set to true. It will dispatch the onRevived event, you can listen to Sprite.events.onRevived for the signal.
- Source:
Returns:
This instance.
- Type
- Phaser.Image