new Sprite(game, x, y, key, frame)
Parameters:
Name | Type | Description |
---|---|---|
game |
Phaser.Game | A reference to the currently running game. |
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. |
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 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:
Members
-
alive
-
- Default Value:
- true
- Source:
Properties:
Name Type Description alive
boolean This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering.
-
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.
- Source:
Properties:
Name Type Description angle
number Gets or sets the Sprites angle of rotation in degrees.
-
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.
-
animations
-
- Source:
Properties:
Name Type Description animations
Phaser.AnimationManager This manages animations of the sprite. You can modify animations through it (see Phaser.AnimationManager)
-
animations
-
- Source:
Properties:
Name Type Description animations
Phaser.AnimationManager This manages animations of the sprite. You can modify animations through it (see Phaser.AnimationManager)
-
autoCull
-
Should this Sprite be automatically culled if out of range of the camera? A culled sprite has its renderable property set to 'false'.
- Default Value:
- false
- Source:
Properties:
Name Type Description autoCull
boolean A flag indicating if the Sprite should be automatically camera culled or not.
-
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.
-
body
-
- Source:
Properties:
Name Type Description body
Phaser.Physics.Arcade.Body By default Sprites have a Phaser.Physics Body attached to them. You can operate physics actions via this property, or null it to skip all physics updates.
-
body
-
- Source:
Properties:
Name Type Description body
Phaser.Physics.Arcade.Body By default Sprites have a Phaser.Physics Body attached to them. You can operate physics actions via this property, or null it to skip all physics updates.
-
bottomLeft
-
- Source:
Properties:
Name Type Description bottomLeft
Phaser.Point A Point containing the bottom left coordinate of the Sprite. Takes rotation and scale into account.
-
bottomRight
-
- Source:
Properties:
Name Type Description bottomRight
Phaser.Point A Point containing the bottom right coordinate of the Sprite. Takes rotation and scale into account.
-
bounds
-
This Rectangle object fully encompasses the Sprite and is updated in real-time. The bounds is the full bounding area after rotation and scale have been taken into account. It should not be modified directly. It's used for Camera culling and physics body alignment.
- Source:
Properties:
Name Type Description bounds
Phaser.Rectangle -
cameraOffset
-
- Source:
Properties:
Name Type Description cameraOffset
Phaser.Point If this Sprite is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered.
-
center
-
- Source:
Properties:
Name Type Description center
Phaser.Point A Point containing the center coordinate of the Sprite. Takes rotation and scale into account.
-
crop
-
You can crop the Sprites texture by modifying the crop properties. For example crop.width = 50 would set the Sprite to only render 50px wide. The crop is only applied if you have set Sprite.cropEnabled to true.
- Source:
Properties:
Name Type Description crop
Phaser.Rectangle The crop Rectangle applied to the Sprite texture before rendering.
-
cropEnabled
-
- Default Value:
- false
- Source:
Properties:
Name Type Description cropEnabled
boolean If true the Sprite.crop property is used to crop the texture before render. Set to false to disable.
-
currentFrame
-
- Source:
Properties:
Name Type Description currentFrame
Phaser.Frame A reference to the currently displayed frame.
-
debug
-
- Default Value:
- false
- Source:
Properties:
Name Type Description debug
boolean Handy flag to use with Game.enableStep
-
debug
-
- Default Value:
- false
- Source:
Properties:
Name Type Description debug
boolean Handy flag to use with Game.enableStep
-
<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.
-
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.
-
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 ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
- Default Value:
- false
- Source:
Properties:
Name Type Description fixedToCamera
boolean Fixes this Sprite to the Camera.
-
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 Cache for display.
-
frame
-
- Source:
Properties:
Name Type Description frame
number Gets or sets the current frame index and updates the Texture Cache for display.
-
frameName
-
- Source:
Properties:
Name Type Description frameName
string Gets or sets the current frame name and updates the Texture Cache for display.
-
frameName
-
- Source:
Properties:
Name Type Description frameName
string Gets or sets the current frame name and updates the Texture Cache for display.
-
game
-
- Source:
Properties:
Name Type Description game
Phaser.Game A reference to the currently running Game.
-
game
-
- Source:
Properties:
Name Type Description game
Phaser.Game A reference to the currently running Game.
-
health
-
- Source:
Properties:
Name Type Description health
number Health value. Used in combination with damage() to allow for quick killing of Sprites.
-
health
-
- Source:
Properties:
Name Type Description health
number Health value. Used in combination with damage() to allow for quick killing of Sprites.
-
height
-
The height of the sprite in pixels, setting this will actually modify the scale to acheive the value desired. If you wish to crop the Sprite instead see the Sprite.crop value.
- Source:
Properties:
Name Type Description height
number The height of the Sprite in pixels.
-
<readonly> inCamera
-
- Source:
Properties:
Name Type Description inCamera
boolean Is this sprite visible to the camera or not?
-
<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 The Input Handler Component.
-
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 a Sprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is activated for this Sprite instance 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 Sprite to receive input events, otherwise false.
-
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.
-
inWorld
-
- Source:
Properties:
Name Type Description inWorld
boolean This value is set to true if the Sprite is positioned within the World, otherwise false.
-
<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.
-
inWorldThreshold
-
- Default Value:
- 0
- Source:
Properties:
Name Type Description inWorldThreshold
number A threshold value applied to the inWorld check. If you don't want a Sprite to be considered "out of the world" until at least 100px away for example then set it to 100.
-
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.
-
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.
-
lifespan
-
If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc. The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
- Default Value:
- 0
- Source:
Properties:
Name Type Description lifespan
number The lifespan of the Sprite (in ms) before it will be killed.
-
lifespan
-
If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc. The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
- Default Value:
- 0
- Source:
Properties:
Name Type Description lifespan
number The lifespan of the Sprite (in ms) before it will be killed.
-
name
-
- Source:
Properties:
Name Type Description name
string The user defined name given to this Sprite.
-
name
-
- Source:
Properties:
Name Type Description name
string The user defined name given to this Sprite.
-
offset
-
- Source:
Properties:
Name Type Description offset
Phaser.Point Corner point defaults. Should not typically be modified.
-
outOfBoundsKill
-
- Default Value:
- false
- Source:
Properties:
Name Type Description outOfBoundsKill
boolean If true the Sprite is killed as soon as Sprite.inWorld is false.
-
outOfBoundsKill
-
- Default Value:
- false
- Source:
Properties:
Name Type Description outOfBoundsKill
boolean If true the Sprite is killed as soon as Sprite.inWorld is false.
-
renderOrderID
-
- Source:
Properties:
Name Type Description renderOrderID
number Used by the Renderer and Input Manager to control picking order.
-
<readonly> renderOrderID
-
- Source:
Properties:
Name Type Description renderOrderID
number The render order ID, reset every frame.
-
textureRegion
-
The rectangular area from the texture that will be rendered.
- Source:
Properties:
Name Type Description textureRegion
Phaser.Rectangle -
topLeft
-
- Source:
Properties:
Name Type Description topLeft
Phaser.Point A Point containing the top left coordinate of the Sprite. Takes rotation and scale into account.
-
topRight
-
- Source:
Properties:
Name Type Description topRight
Phaser.Point A Point containing the top right coordinate of the Sprite. Takes rotation and scale into account.
-
<readonly> type
-
- Source:
Properties:
Name Type Description type
number The const type of this object.
-
<readonly> type
-
- Source:
Properties:
Name Type Description type
number The const type of this object.
-
width
-
The width of the sprite in pixels, setting this will actually modify the scale to acheive the value desired. If you wish to crop the Sprite instead see the Sprite.crop value.
- Source:
Properties:
Name Type Description width
number The width of the Sprite in pixels.
-
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.
-
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.
-
<readonly> worldCenterX
-
- Source:
Properties:
Name Type Description worldCenterX
number The center of the Sprite in world coordinates.
-
<readonly> worldCenterY
-
- Source:
Properties:
Name Type Description worldCenterY
number The center of the Sprite in world coordinates.
-
x
-
- Source:
Properties:
Name Type Description x
number The x coordinate in world space of this Sprite.
-
y
-
- Source:
Properties:
Name Type Description y
number The y coordinate in world space of this Sprite.
Methods
-
bringToTop()
-
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:
(Phaser.Sprite) This instance.
-
bringToTop()
-
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:
(Phaser.Sprite) This instance.
-
centerOn(x, y)
-
Moves the sprite so its center is located on the given x and y coordinates. Doesn't change the anchor point of the sprite.
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:
(Phaser.Sprite) This instance.
-
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:
-
damage(amount)
-
Damages the Sprite, this removes the given amount from the Sprites health property. If health is then taken below zero Sprite.kill is called.
Parameters:
Name Type Description amount
number The amount to subtract from the Sprite.health value.
- Source:
Returns:
(Phaser.Sprite) This instance.
-
damage(amount)
-
Damages the Sprite, this removes the given amount from the Sprites health property. If health is then taken below zero Sprite.kill is called.
Parameters:
Name Type Description amount
number The amount to subtract from the Sprite.health value.
- Source:
Returns:
(Phaser.Sprite) This instance.
-
deltaX() → {number}
-
Returns the delta x value. The difference between Sprite.x now and in the previous step.
- Source:
Returns:
The delta value. Positive if the motion was to the right, negative if to the left.
- Type
- number
-
deltaY() → {number}
-
Returns the delta x value. The difference between Sprite.y now and in the previous step.
- Source:
Returns:
The delta value. Positive if the motion was downwards, negative if upwards.
- Type
- number
-
destroy()
-
Destroy this Graphics instance.
- 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:
-
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:
-
drawPolygon()
-
/* Draws a {Phaser.Polygon} or a {PIXI.Polygon} filled
- Source:
-
getLocalPosition(p, x, y) → {Phaser.Point}
-
Gets the local position of a coordinate relative to the Sprite, factoring in rotation and scale. Mostly only used internally.
Parameters:
Name Type Description p
Phaser.Point The Point object to store the results in.
x
number x coordinate within the Sprite to translate.
y
number y coordinate within the Sprite to translate.
- Source:
Returns:
The translated point.
- Type
- Phaser.Point
-
getLocalUnmodifiedPosition(p, gx, gy) → {Phaser.Point}
-
Gets the local unmodified position of a coordinate relative to the Sprite, factoring in rotation and scale. Mostly only used internally by the Input Manager, but also useful for custom hit detection.
Parameters:
Name Type Description p
Phaser.Point The Point object to store the results in.
gx
number x coordinate within the Sprite to translate.
gy
number y coordinate within the Sprite to translate.
- Source:
Returns:
The translated point.
- Type
- Phaser.Point
-
kill()
-
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:
(Phaser.Sprite) This instance.
-
kill()
-
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:
(Phaser.Sprite) This instance.
-
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:
-
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:
-
play(name, frameRate, loop, killOnComplete) → {Phaser.Animation}
-
Play an animation based on the given key. The animation should previously have been added via sprite.animations.add() If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
Parameters:
Name Type Argument Default Description name
string The name of the animation to be played, e.g. "fire", "walk", "jump".
frameRate
number <optional>
null The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
loop
boolean <optional>
false Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
killOnComplete
boolean <optional>
false If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
- Source:
Returns:
A reference to playing Animation instance.
- Type
- Phaser.Animation
-
play(name, frameRate, loop, killOnComplete) → {Phaser.Animation}
-
Play an animation based on the given key. The animation should previously have been added via sprite.animations.add() If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
Parameters:
Name Type Argument Default Description name
string The name of the animation to be played, e.g. "fire", "walk", "jump".
frameRate
number <optional>
null The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
loop
boolean <optional>
false Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
killOnComplete
boolean <optional>
false If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
- Source:
Returns:
A reference to playing Animation instance.
- Type
- Phaser.Animation
-
postUpdate()
-
Internal function called by the World postUpdate cycle.
- Source:
-
postUpdate()
-
Internal function called by the World postUpdate cycle.
- Source:
-
preUpdate()
-
Automatically called by World.preUpdate. Handles cache updates, lifespan checks, animation updates and physics updates.
- Source:
-
preUpdate()
-
Automatically called by World.preUpdate.
- Source:
-
reset(x, y, health)
-
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. Also resets the outOfBounds state and health values. If the Sprite has a physics body that too is reset.
Parameters:
Name Type Argument Default 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.
health
number <optional>
1 The health to give the Sprite.
- Source:
Returns:
(Phaser.Sprite) This instance.
-
reset(x, y, health)
-
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. Also resets the outOfBounds state and health values. If the Sprite has a physics body that too is reset.
Parameters:
Name Type Argument Default 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.
health
number <optional>
1 The health to give the Sprite.
- Source:
Returns:
(Phaser.Sprite) This instance.
-
resetCrop()
-
Resets the Sprite.crop value back to the frame dimensions.
- Source:
-
revive(health)
-
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.
Parameters:
Name Type Argument Default Description health
number <optional>
1 The health to give the Sprite.
- Source:
Returns:
(Phaser.Sprite) This instance.
-
revive(health)
-
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.
Parameters:
Name Type Argument Default Description health
number <optional>
1 The health to give the Sprite.
- Source:
Returns:
(Phaser.Sprite) This instance.
-
updateAnimation()
-
Internal function called by preUpdate.
- Source:
-
updateBounds()
-
Internal function called by preUpdate.
- Source:
-
updateCache()
-
Internal function called by preUpdate.
- Source:
-
updateCrop()
-
Internal function called by preUpdate.
- Source: