new TileSprite(game, x, y, width, height, key, frame)
A TileSprite is a Sprite whos texture is set to repeat and can be scrolled. As it scrolls the texture repeats (wraps) on the edges.
Parameters:
Name | Type | Description |
---|---|---|
game |
Phaser.Game | Current game instance. |
x |
number | X position of the new tileSprite. |
y |
number | Y position of the new tileSprite. |
width |
number | the width of the tilesprite. |
height |
number | the height of the tilesprite. |
key |
string | Phaser.RenderTexture | 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:
Extends
Members
-
alive
-
- Inherited From:
- 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.
-
anchor
-
The anchor sets the origin point of the texture. The default is 0,0 this means the textures 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
- Inherited From:
- Source:
Properties:
Name Type Description anchor
Phaser.Point The anchor around which rotation and scaling takes place.
-
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.
- Inherited From:
- Source:
Properties:
Name Type Description angle
number Gets or sets the Sprites angle of rotation in degrees.
-
animations
-
- Inherited From:
- 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'.
- Inherited From:
- Default Value:
- false
- Source:
Properties:
Name Type Description autoCull
boolean A flag indicating if the Sprite should be automatically camera culled or not.
-
body
-
- Inherited From:
- 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
-
- Inherited From:
- 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
-
- Inherited From:
- 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.
- Inherited From:
- Source:
Properties:
Name Type Description bounds
Phaser.Rectangle -
cameraOffset
-
- Inherited From:
- 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
-
- Inherited From:
- 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.
- Inherited From:
- Source:
Properties:
Name Type Description crop
Phaser.Rectangle The crop Rectangle applied to the Sprite texture before rendering.
-
cropEnabled
-
- Inherited From:
- 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
-
- Inherited From:
- Source:
Properties:
Name Type Description currentFrame
Phaser.Frame A reference to the currently displayed frame.
-
events
-
- Inherited From:
- 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
-
- Inherited From:
- 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.
- Inherited From:
- Default Value:
- false
- Source:
Properties:
Name Type Description fixedToCamera
boolean Fixes this Sprite to the Camera.
-
frame
-
- Inherited From:
- Source:
Properties:
Name Type Description frame
number Gets or sets the current frame index and updates the Texture Cache for display.
-
frameName
-
- Inherited From:
- Source:
Properties:
Name Type Description frameName
string Gets or sets the current frame name and updates the Texture Cache for display.
-
game
-
- Inherited From:
- Source:
Properties:
Name Type Description game
Phaser.Game A reference to the currently running Game.
-
group
-
- Inherited From:
- Source:
Properties:
Name Type Description group
Phaser.Group The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
-
health
-
- Inherited From:
- 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.
- Inherited From:
- Source:
Properties:
Name Type Description height
number The height of the Sprite in pixels.
-
<readonly> inCamera
-
- Inherited From:
- Source:
Properties:
Name Type Description inCamera
boolean Is this sprite visible to the camera or not?
-
input
-
- Inherited From:
- Source:
Properties:
Name Type Description input
Phaser.InputHandler The Input Handler Component.
-
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.
- Inherited From:
- Source:
Properties:
Name Type Description inputEnabled
boolean Set to true to allow this Sprite to receive input events, otherwise false.
-
inWorld
-
- Inherited From:
- Source:
Properties:
Name Type Description inWorld
boolean This value is set to true if the Sprite is positioned within the World, otherwise false.
-
inWorldThreshold
-
- Inherited From:
- 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
-
- Inherited From:
- 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.
- Inherited From:
- Default Value:
- 0
- Source:
Properties:
Name Type Description lifespan
number The lifespan of the Sprite (in ms) before it will be killed.
-
name
-
- Inherited From:
- Source:
Properties:
Name Type Description name
string The user defined name given to this Sprite.
-
offset
-
- Inherited From:
- Source:
Properties:
Name Type Description offset
Phaser.Point Corner point defaults. Should not typically be modified.
-
outOfBoundsKill
-
- Inherited From:
- Default Value:
- false
- Source:
Properties:
Name Type Description outOfBoundsKill
boolean If true the Sprite is killed as soon as Sprite.inWorld is false.
-
renderOrderID
-
- Inherited From:
- Source:
Properties:
Name Type Description renderOrderID
number Used by the Renderer and Input Manager to control picking order.
-
scale
-
- Inherited From:
- Source:
Properties:
Name Type Description scale
Phaser.Point The scale of the Sprite when rendered. By default it's set to 1 (no scale). You can modify it via scale.x or scale.y or scale.setTo(x, y). A value of 1 means no change to the scale, 0.5 means "half the size", 2 means "twice the size", etc.
-
texture
-
- Source:
Properties:
Name Type Description texture
PIXI.Texture The texture that the sprite renders with.
-
textureRegion
-
The rectangular area from the texture that will be rendered.
- Inherited From:
- Source:
Properties:
Name Type Description textureRegion
Phaser.Rectangle -
tilePosition
-
- Source:
Properties:
Name Type Description tilePosition
Phaser.Point The offset position of the image that is being tiled.
-
tileScale
-
- Source:
Properties:
Name Type Description tileScale
Phaser.Point The scaling of the image that is being tiled.
-
topLeft
-
- Inherited From:
- 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
-
- Inherited From:
- 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.
-
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.
- Inherited From:
- Source:
Properties:
Name Type Description width
number The width of the Sprite in pixels.
-
world
-
- Inherited From:
- 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.
-
x
-
- Inherited From:
- Source:
Properties:
Name Type Description x
number The x coordinate in world space of this Sprite.
-
y
-
- Inherited From:
- 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.
- Inherited From:
- 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.
- Inherited From:
- 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.
- Inherited From:
- Source:
Returns:
(Phaser.Sprite) This instance.
-
destroy()
-
Destroy this Graphics instance.
- Inherited From:
- 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.
- Inherited From:
- Source:
-
getLocalPosition(p, x, y, sx, sy) → {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 x coordinate within the Sprite to translate.
sx
number Scale factor to be applied.
sy
number Scale factor to be applied.
- Inherited From:
- Source:
Returns:
The translated point.
- Type
- Phaser.Point
-
getLocalUnmodifiedPosition(p, x, y) → {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.
x
number x coordinate within the Sprite to translate.
y
number x coordinate within the Sprite to translate.
- Inherited From:
- 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.
- Inherited From:
- 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.
- Inherited From:
- 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.
- Inherited From:
- Source:
Returns:
A reference to playing Animation instance.
- Type
- Phaser.Animation
-
postUpdate()
-
Internal function called by the World postUpdate cycle.
- Inherited From:
- Source:
-
preUpdate()
-
Automatically called by World.preUpdate. Handles cache updates, lifespan checks, animation updates and physics updates.
- Inherited From:
- 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.
- Inherited From:
- Source:
Returns:
(Phaser.Sprite) This instance.
-
resetCrop()
-
Resets the Sprite.crop value back to the frame dimensions.
- Inherited From:
- 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.
- Inherited From:
- Source:
Returns:
(Phaser.Sprite) This instance.
-
updateAnimation()
-
Internal function called by preUpdate.
- Inherited From:
- Source:
-
updateBounds()
-
Internal function called by preUpdate.
- Inherited From:
- Source:
-
updateCache()
-
Internal function called by preUpdate.
- Inherited From:
- Source:
-
updateCrop()
-
Internal function called by preUpdate.
- Inherited From:
- Source: