new Sprite(texture)
The Sprite object is the base for all textured objects that are rendered to the screen
Parameters:
| Name | Type | Description |
|---|---|---|
texture |
Texture | The texture for this sprite |
Extends
Members
-
<static> defaultAnchor : Object
-
Type:
- Object
- Default Value:
-
- {"x":0,"y":0}
- Source:
- src/pixi/display/Sprite.js line 128
Properties:
Name Type Description PIXI.Sprite.defaultAnchorA Point-like object.
-
alpha : number
-
The alpha value of this DisplayObject. A value of 1 is fully opaque. A value of 0 is transparent. Please note that an object with an alpha value of 0 is skipped during the render pass.
The value of this property does not reflect any alpha values set further up the display list. To obtain that value please see the
worldAlphaproperty.Type:
- number
- Inherited From:
- Default Value:
-
- 1
- Source:
- src/pixi/display/DisplayObject.js line 73
-
anchor : Point
-
The anchor sets the origin point of the texture. The default (0, 0) is the top left. (0.5, 0.5) is the center. (1, 1) is the bottom right.
You can modify the default values in PIXI.Sprite.defaultAnchor.
Type:
- Point
-
blendMode : Number
-
The blend mode to be applied to the sprite. Set to PIXI.blendModes.NORMAL to remove any blend mode.
Warning: You cannot have a blend mode and a filter active on the same Sprite. Doing so will render the sprite invisible.
Type:
- Number
- Default Value:
-
- PIXI.blendModes.NORMAL;
- Source:
- src/pixi/display/Sprite.js line 93
-
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.
Transparent areas adjoining the edges may be removed (#283).
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 tonullto remove an existing cached bitmap.Type:
- boolean
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 794
-
<readonly> children : Array(DisplayObject)
-
[read-only] The array of children of this container.
Type:
- Array(DisplayObject)
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 24
-
exists : Boolean
-
Controls if this Sprite is processed by the core Phaser game loops and Group loops (except Phaser.Group#update).
Type:
- Boolean
- Default Value:
-
- true
- Source:
- src/pixi/display/Sprite.js line 112
-
filterArea : Rectangle
-
The rectangular area used by filters when rendering a shader for this DisplayObject.
Type:
- Rectangle
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 202
-
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:
- Array
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 741
-
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:
- Rectangle | Circle | Ellipse | Polygon
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 96
-
ignoreChildInput : boolean
-
If
ignoreChildInputisfalseit will allow this objects children to be considered as valid for Input events.If this property is
truethen the children will not be considered as valid for Input events.Note that this property isn't recursive: only immediate children are influenced, it doesn't scan further down.
Type:
- boolean
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 35
-
mask : Phaser.Graphics
-
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 tonullto remove an existing mask.Type:
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 706
-
<readonly> parent : PIXI.DisplayObjectContainer
-
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:
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 117
-
pivot : PIXI.Point
-
The pivot point of this DisplayObject that it rotates around. The values are expressed in pixel values.
Type:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 49
-
position : PIXI.Point
-
The coordinates, in pixels, of this DisplayObject, relative to its parent container.
The value of this property does not reflect any positioning happening further up the display list. To obtain that value please see the
worldPositionproperty.Type:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 29
-
renderable : boolean
-
Should this DisplayObject be rendered by the renderer? An object with a renderable value of
falseis skipped during the render pass.Type:
- boolean
- Inherited From:
- Overrides:
- Source:
- src/pixi/display/DisplayObject.js line 105
-
rotation : number
-
The rotation of this DisplayObject. The value is given, and expressed, in radians, and is based on a right-handed orientation.
The value of this property does not reflect any rotation happening further up the display list. To obtain that value please see the
worldRotationproperty.Type:
- number
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 61
-
scale : PIXI.Point
-
The scale of this DisplayObject. A scale of 1:1 represents the DisplayObject at its default size. A value of 0.5 would scale this DisplayObject by half, and so on.
The value of this property does not reflect any scaling happening further up the display list. To obtain that value please see the
worldScaleproperty.Type:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 41
-
shader : Phaser.Filter
-
The shader that will be used to render this Sprite. Set to null to remove a current shader.
Type:
- Default Value:
-
- null
- Source:
- src/pixi/display/Sprite.js line 103
-
texture : Texture
-
The texture that the sprite is using
Type:
- Texture
-
tint : Number
-
The tint applied to the sprite. This is a hex value. A value of 0xFFFFFF will remove any tint effect.
Type:
- Number
- Default Value:
-
- 0xFFFFFF
- Source:
- src/pixi/display/Sprite.js line 63
-
tintedTexture : Canvas
-
A canvas that contains the tinted version of the Sprite (in Canvas mode, WebGL doesn't populate this)
Type:
- Canvas
- Default Value:
-
- null
- Source:
- src/pixi/display/Sprite.js line 82
-
visible : boolean
-
The visibility of this DisplayObject. A value of
falsemakes the object invisible. A value oftruemakes it visible. Please note that an object with a visible value offalseis skipped during the render pass. Equally a DisplayObject with visible false will not render any of its children.The value of this property does not reflect any visible values set further up the display list. To obtain that value please see the
worldVisibleproperty.Type:
- boolean
- Inherited From:
- Default Value:
-
- true
- Source:
- src/pixi/display/DisplayObject.js line 87
-
<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
alphaproperty.Note: This property is only updated at the end of the
updateTransformcall, 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:
- number
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 133
-
<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
updateTransformcall, 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:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 163
-
<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
updateTransformcall, 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:
- number
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 193
-
<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
updateTransformcall, 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:
- PIXI.Point
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 178
-
<readonly> worldTransform : Phaser.Matrix
-
The current transform of this DisplayObject.
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
updateTransformcall, 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:
- Inherited From:
- Overrides:
- Source:
- src/pixi/display/DisplayObject.js line 148
-
worldVisible : boolean
-
Indicates if this DisplayObject is visible, based on it, and all of its parents,
visibleproperty values.Type:
- boolean
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 663
-
x : number
-
The horizontal position of the DisplayObject, in pixels, relative to its parent. If you need the world position of the DisplayObject, use
DisplayObject.worldPositioninstead.Type:
- number
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 619
-
y : number
-
The vertical position of the DisplayObject, in pixels, relative to its parent. If you need the world position of the DisplayObject, use
DisplayObject.worldPositioninstead.Type:
- number
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 641
Methods
-
addChild(child)
-
Adds a child to the container.
Parameters:
Name Type Description childDisplayObject The DisplayObject to add to the container
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 42
Returns:
The child that was added.
- Type
- DisplayObject
-
addChildAt(child, index)
-
Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown
Parameters:
Name Type Description childDisplayObject The child to add
indexNumber The index to place the child in
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 55
Returns:
The child that was added.
- Type
- DisplayObject
-
contains(child)
-
Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself.
Parameters:
Name Type Description childDisplayObject - Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 449
Returns:
- Type
- boolean
-
destroy()
-
Destroy this DisplayObject.
Removes any cached sprites, sets renderable flag to false, and nulls filters, bounds and mask.
Also iteratively calls
destroyon any children.- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 252
-
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 resolutionnumber <optional>
1 The resolution of the texture being generated.
scaleModenumber <optional>
PIXI.scaleModes.DEFAULT See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values.
rendererPIXI.CanvasRenderer | PIXI.WebGLRenderer The renderer used to generate the texture.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 441
Returns:
- A RenderTexture containing an image of this DisplayObject at the time it was invoked.
- Type
- Phaser.RenderTexture
-
getBounds(matrix)
-
Returns the bounds of the Sprite as a rectangle. The bounds calculation takes the worldTransform into account.
It is important to note that the transform is not updated when you call this method. So if this Sprite is the child of a Display Object which has had its transform updated since the last render pass, those changes will not yet have been applied to this Sprites worldTransform. If you need to ensure that all parent transforms are factored into this getBounds operation then you should call
updateTransformon the root most object in this Sprites display list first.Parameters:
Name Type Description matrixMatrix the transformation matrix of the sprite
- Overrides:
- Source:
- src/pixi/display/Sprite.js line 208
Returns:
the framing rectangle
- Type
- Rectangle
-
getChildAt(index)
-
Returns the child at the specified index
Parameters:
Name Type Description indexNumber The index to get the child from
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 153
Returns:
The child at the given index, if any.
- Type
- DisplayObject
-
getChildIndex(child)
-
Returns the index position of a child DisplayObject instance
Parameters:
Name Type Description childDisplayObject The DisplayObject instance to identify
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 112
Returns:
The index position of the child display object to identify
- Type
- Number
-
getLocalBounds()
-
Retrieves the non-global local bounds of the Sprite as a rectangle. The calculation takes all visible children into consideration.
- Overrides:
- Source:
- src/pixi/display/Sprite.js line 324
Returns:
The rectangular bounding area
- Type
- Rectangle
-
preUpdate()
-
To be overridden by classes that require it.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 432
-
removeChild(child)
-
Removes a child from the container.
Parameters:
Name Type Description childDisplayObject The DisplayObject to remove
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 171
Returns:
The child that was removed.
- Type
- DisplayObject
-
removeChildAt(index)
-
Removes a child from the specified index position.
Parameters:
Name Type Description indexNumber The index to get the child from
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 191
Returns:
The child that was removed.
- Type
- DisplayObject
-
removeChildren(beginIndex, endIndex)
-
Removes all children from this container that are within the begin and end indexes.
Parameters:
Name Type Description beginIndexNumber The beginning position. Default value is 0.
endIndexNumber The ending position. Default value is size of the container.
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 213
-
setChildIndex(child, index)
-
Changes the position of an existing child in the display object container
Parameters:
Name Type Description childDisplayObject The child DisplayObject instance for which you want to change the index number
indexNumber The resulting index number for the child display object
- Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 132
-
setTexture(texture [, destroy])
-
Sets the texture of the sprite. Be warned that this doesn't remove or destroy the previous texture this Sprite was using.
Parameters:
Name Type Argument Default Description textureTexture The PIXI texture that is displayed by the sprite
destroyboolean <optional>
false Call Texture.destroy on the current texture before replacing it with the new one?
-
swapChildren(child, child2)
-
Swaps the position of 2 Display Objects within this container.
Parameters:
Name Type Description childDisplayObject child2DisplayObject - Inherited From:
- Source:
- src/pixi/display/DisplayObjectContainer.js line 85
-
toGlobal(position)
-
Calculates the global position of this DisplayObject, based on the position given.
Parameters:
Name Type Description positionPIXI.Point The global position to calculate from.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 483
Returns:
- A point object representing the position of this DisplayObject based on the global position given.
- Type
- PIXI.Point
-
toLocal(position [, from])
-
Calculates the local position of this DisplayObject, relative to another point.
Parameters:
Name Type Argument Description positionPIXI.Point The world origin to calculate from.
fromPIXI.DisplayObject <optional>
An optional DisplayObject to calculate the global position from.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 498
Returns:
- A point object representing the position of this DisplayObject based on the global position given.
- Type
- PIXI.Point
-
updateCache()
-
If this DisplayObject has a cached Sprite, this method generates and updates it.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 469
Returns:
- A reference to this DisplayObject.
- Type
- PIXI.DisplayObject
-
updateTransform( [parent])
-
Updates the transform matrix this DisplayObject uses for rendering.
If the object has no parent, and no parent parameter is provided, it will default to Phaser.Game.World as the parent transform to use. If that is unavailable the transform fails to take place.
The
parentparameter has priority over the actual parent. Use it as a parent override. Setting it does not change the actual parent of this DisplayObject.Calling this method updates the
worldTransform,worldAlpha,worldPosition,worldScaleandworldRotationproperties.If a
transformCallbackhas been specified, it is called at the end of this method, and is passed the new, updated, worldTransform property, along with the parent transform used.Parameters:
Name Type Argument Description parentPIXI.DisplayObjectContainer <optional>
Optional parent to calculate this DisplayObjects transform from.
- Inherited From:
- Source:
- src/pixi/display/DisplayObject.js line 289
Returns:
- A reference to this DisplayObject.
- Type
- PIXI.DisplayObject