A reference to the Texture Manager this Texture belongs to.
The unique string-based key of this Texture.
The canvas element that is used as the base of this texture.
The width of the canvas.
The height of the canvas.
An ArrayBuffer the same size as the context ImageData.
ReadonlycanvasThe source Canvas Element.
ReadonlycontextThe 2D Canvas Rendering Context.
Any additional data that was set in the source JSON (if any), or any extra data you'd like to store relating to this texture.
A Uint8ClampedArray view into the buffer.
Use the update method to populate this when the canvas changes.
Note that this is unavailable in some browsers, such as Epic Browser, due to their security restrictions.
An array of TextureSource data instances. Used to store additional data images, such as normal maps or specular maps.
The name of the first frame of the Texture.
A key-value object pair associating the unique Frame keys with the Frames objects.
The total number of Frames in this Texture, including the __BASE frame.
A Texture will always contain at least 1 frame because every Texture contains a __BASE frame by default,
in addition to any extra frames that have been added to it, such as when parsing a Sprite Sheet or Texture Atlas.
ReadonlyheightThe height of the Canvas.
This property is read-only, if you wish to change it use the setSize method.
The context image data.
Use the update method to populate this when the canvas changes.
The unique string-based key of this Texture.
A reference to the Texture Manager this Texture belongs to.
An Uint32Array view into the buffer.
Controls whether shaders using this texture should apply smooth interpolation when rendering pixel art. When enabled, the renderer uses shader-based smoothing to reduce the jagged appearance of upscaled pixel art. This relies on shader support.
If null, the game default will be used.
An array of TextureSource instances. These are unique to this Texture and contain the actual Image (or Canvas) data.
ReadonlywidthThe width of the Canvas.
This property is read-only, if you wish to change it use the setSize method.
Adds a new Frame to this Texture.
A Frame is a rectangular region of a TextureSource with a unique index or string-based key.
The name given must be unique within this Texture. If it already exists, this method will return null.
The name of this Frame. The name is unique within the Texture.
The index of the TextureSource that this Frame is a part of.
The x coordinate of the top-left of this Frame.
The y coordinate of the top-left of this Frame.
The width of this Frame.
The height of this Frame.
The Frame that was added to this Texture, or null if the given name already exists.
Clears the given region of this Canvas Texture, resetting it back to transparent. If no region is given, the whole Canvas Texture is cleared.
Optionalx: number
The x coordinate of the top-left of the region to clear. Default 0.
Optionaly: number
The y coordinate of the top-left of the region to clear. Default 0.
Optionalwidth: number
The width of the region.
Optionalheight: number
The height of the region.
Optionalupdate: boolean
Update the internal ImageData buffer and arrays. Default true.
The Canvas Texture.
Destroys this Texture and releases references to its sources and frames.
Draws the given Image or Canvas element to this CanvasTexture, then updates the internal ImageData buffer and arrays.
The x coordinate to draw the source at.
The y coordinate to draw the source at.
The element to draw to this canvas.
Optionalupdate: boolean
Update the internal ImageData buffer and arrays. Default true.
This CanvasTexture.
Draws the given texture frame to this CanvasTexture, then updates the internal ImageData buffer and arrays.
The unique string-based key of the Texture.
Optionalframe: string | number
The string-based name, or integer based index, of the Frame to get from the Texture.
Optionalx: number
The x coordinate to draw the source at. Default 0.
Optionaly: number
The y coordinate to draw the source at. Default 0.
Optionalupdate: boolean
Update the internal ImageData buffer and arrays. Default true.
This CanvasTexture.
Gets a Frame from this Texture based on either the key or the index of the Frame.
In a Texture Atlas Frames are typically referenced by a key. In a Sprite Sheet Frames are referenced by an index. Passing no value for the name returns the base texture.
Optionalname: string | number
The string-based name, or integer based index, of the Frame to get from this Texture.
The Texture Frame.
Gets the Canvas Element.undefined
The Canvas DOM element this texture is using.
Gets the 2D Canvas Rendering Context.undefined
The Canvas Rendering Context this texture is using.
Gets an ImageData region from this CanvasTexture from the position and size specified.
You can write this back using CanvasTexture.putData, or manipulate it.
The x coordinate of the top-left of the area to get the ImageData from. Must lay within the dimensions of this CanvasTexture and be an integer.
The y coordinate of the top-left of the area to get the ImageData from. Must lay within the dimensions of this CanvasTexture and be an integer.
The width of the rectangle from which the ImageData will be extracted. Positive values are to the right, and negative to the left.
The height of the rectangle from which the ImageData will be extracted. Positive values are down, and negative are up.
The ImageData extracted from this CanvasTexture.
Given a Frame name, return the data source image it uses to render with. You can use this to get the normal map for an image for example.
This will return the actual DOM Image.
Optionalname: string | number
The string-based name, or integer based index, of the Frame to get from this Texture.
The DOM Image or Canvas Element.
Based on the given Texture Source Index, this method will get all of the Frames using that source and then work out the bounds that they encompass, returning them in an object.
This is useful if this Texture is, for example, a sprite sheet within an Atlas, and you need to know the total bounds of the sprite sheet.
OptionalsourceIndex: number
The index of the TextureSource to get the Frame bounds from. Default 0.
An object containing the bounds of the Frames using the given Texture Source Index.
Returns an array with all of the names of the Frames in this Texture.
Useful if you want to randomly assign a Frame to a Game Object, as you can pick a random element from the returned array.
OptionalincludeBase: boolean
Include the __BASE Frame in the output array? Default false.
An array of all Frame names in this Texture.
Returns an array of all the Frames in the given TextureSource.
The index of the TextureSource to get the Frames from.
OptionalincludeBase: boolean
Include the __BASE Frame in the output array? Default false.
An array of Texture Frames.
Returns the Image Data index for the given pixel in this CanvasTexture.
The index can be used to read directly from the this.data array.
The index points to the red value in the array. The subsequent 3 indexes point to green, blue and alpha respectively.
The x coordinate of the pixel to get. Must lay within the dimensions of this CanvasTexture and be an integer.
The y coordinate of the pixel to get. Must lay within the dimensions of this CanvasTexture and be an integer.
The index of the pixel in the image data array, or -1 if the coordinates are out of bounds.
Get the color of a specific pixel from this texture and store it in a Color object.
If you have drawn anything to this CanvasTexture since it was created you must call CanvasTexture.update to refresh the array buffer,
otherwise this may return out of date color values, or worse - throw a run-time error as it tries to access an array element that doesn't exist.
The x coordinate of the pixel to get. Must lay within the dimensions of this CanvasTexture and be an integer.
The y coordinate of the pixel to get. Must lay within the dimensions of this CanvasTexture and be an integer.
Optionalout: Color
A Color object to store the pixel values in. If not provided a new Color object will be created.
An object with the red, green, blue and alpha values set in the r, g, b and a properties.
Returns an array containing all of the pixels in the given region.
If the requested region extends outside the bounds of this CanvasTexture, the region is truncated to fit.
If you have drawn anything to this CanvasTexture since it was created you must call CanvasTexture.update to refresh the array buffer,
otherwise this may return out of date color values, or worse - throw a run-time error as it tries to access an array element that doesn't exist.
Optionalx: number
The x coordinate of the top-left of the region. Must lay within the dimensions of this CanvasTexture and be an integer. Default 0.
Optionaly: number
The y coordinate of the top-left of the region. Must lay within the dimensions of this CanvasTexture and be an integer. Default 0.
Optionalwidth: number
The width of the region to get. Must be an integer. Defaults to the canvas width if not given.
Optionalheight: number
The height of the region to get. Must be an integer. If not given will be set to the width.
A 2d array of Pixel objects.
Given a Frame name, return the source image it uses to render with.
This will return the actual DOM Image or Canvas element.
Optionalname: string | number
The string-based name, or integer based index, of the Frame to get from this Texture.
The DOM Image, Canvas Element or Render Texture.
Takes the given TextureSource and returns the index of it within this Texture. If it's not in this Texture, it returns -1. Unless this Texture has multiple TextureSources, such as with a multi-atlas, this method will always return zero or -1.
The TextureSource to check.
The index of the TextureSource within this Texture, or -1 if not in this Texture.
Checks to see if a Frame matching the given key exists within this Texture.
The key of the Frame to check for.
True if a Frame with the matching key exists in this Texture.
Puts the ImageData into the context of this CanvasTexture at the given coordinates.
The ImageData to put at the given location.
The x coordinate to put the imageData. Must lay within the dimensions of this CanvasTexture and be an integer.
The y coordinate to put the imageData. Must lay within the dimensions of this CanvasTexture and be an integer.
OptionaldirtyX: number
Horizontal position (x coordinate) of the top-left corner from which the image data will be extracted. Default 0.
OptionaldirtyY: number
Vertical position (y coordinate) of the top-left corner from which the image data will be extracted. Default 0.
OptionaldirtyWidth: number
Width of the rectangle to be painted. Defaults to the width of the image data.
OptionaldirtyHeight: number
Height of the rectangle to be painted. Defaults to the height of the image data.
This CanvasTexture.
This should be called manually if you are running under WebGL. It will refresh the WebGLTexture from the Canvas source. Only call this if you know that the canvas has changed, as there is a significant GPU texture allocation cost involved in doing so.undefined
This CanvasTexture.
Removes the given Frame from this Texture. The Frame is destroyed immediately.
Any Game Objects using this Frame should stop using it before you remove it, as it does not happen automatically.
The key of the Frame to remove.
True if a Frame with the matching key was removed from this Texture.
Adds a data source image to this Texture.
An example of a data source image would be a normal map, where all of the Frames for this Texture equally apply to the normal map.
There can only be one data source per 'regular' source entry.
The source image data.
OptionalstartIndex: number
The index of the first source to update. If there are multiple data elements, they will be applied to subsequent indices. Default 0.
Optionalrenew: boolean
Whether to destroy the existing source and create a new one, if a source is already in the array at an index. Default false.
Optionalwidth: number
Width to use, if not available from the data (e.g. using a Uint8Array)
Optionalheight: number
Height to use, if not available from the data (e.g. using a Uint8Array)
Sets the Filter Mode for this Texture.
The mode can be either Linear, the default, or Nearest.
For pixel-art you should use Nearest.
The mode applies to the entire Texture, not just a specific Frame of it.
The Filter Mode.
Sets a pixel in the CanvasTexture to the given color and alpha values.
This is an expensive operation to run in large quantities, so use sparingly.
The x coordinate of the pixel to set. Must lay within the dimensions of this CanvasTexture and be an integer.
The y coordinate of the pixel to set. Must lay within the dimensions of this CanvasTexture and be an integer.
The red color value. A number between 0 and 255.
The green color value. A number between 0 and 255.
The blue color value. A number between 0 and 255.
Optionalalpha: number
The alpha value. A number between 0 and 255. Default 255.
This CanvasTexture.
Changes the size of this Canvas Texture.
The new width of the Canvas.
Optionalheight: number
The new height of the Canvas. If not given it will use the width as the height.
The Canvas Texture.
Set the smoothPixelArt property for this Texture.
If true, it will also run setFilter(Phaser.Textures.FilterMode.LINEAR)
to enable the necessary linear filtering.
If false, it will not change the filter mode, as it doesn't know
the previous state, nor is it necessary to change it.
Set to true to enable smooth pixel art interpolation and apply LINEAR filtering. Set to false to disable smooth interpolation without changing the filter mode. Set to null to use the game's default setting.
Set the source data for this Texture. By default, this will update any existing sources, effectively overwriting them.
It's advisable to only swap between textures of the same size, as the dimensions of game objects are often derived from texture size and might change in unexpected ways if they don't match.
Any related dataSource members must be updated.
See Phaser.Textures.Texture#setDataSource.
The source image data.
OptionalstartIndex: number
The index of the first source to update. If there are multiple data elements, they will be applied to subsequent indices. Default 0.
Optionalrenew: boolean
Whether to destroy the existing source and create a new one, if a source is already in the array at an index. Default false.
Optionalwidth: number
Width to use, if not available from the data (e.g. using a Uint8Array)
Optionalheight: number
Height to use, if not available from the data (e.g. using a Uint8Array)
Set the wrap mode for this Texture.
This is only available for WebGL.
The wrap mode can be one of the following:
Note that only CLAMP_TO_EDGE is supported for non-power of two textures. If another wrap mode is specified for such a texture, it will be ignored.
This re-creates the imageData from the current context.
It then re-builds the ArrayBuffer, the data Uint8ClampedArray reference and the pixels Uint32Array.
Warning: This is a very expensive operation, so use it sparingly.undefined
This CanvasTexture.
A Canvas Texture is a special kind of Texture that is backed by an HTML Canvas Element as its source.
You can use the properties of this texture to draw to the canvas element directly, using all of the standard canvas operations available in the browser. Any Game Object can be given this texture and will render with it.
Note: When running under WebGL the Canvas Texture needs to re-generate its base WebGLTexture and reupload it to the GPU every time you modify it, otherwise the changes you make to this texture will not be visible. To do this you should call
CanvasTexture.refresh()once you are finished with your changes to the canvas. Try and keep this to a minimum, especially on large canvas sizes, or you may inadvertently thrash the GPU by constantly uploading texture data to it. This restriction does not apply if using the Canvas Renderer.It starts with only one frame that covers the whole of the canvas. You can add further frames, that specify sections of the canvas using the
addmethod.Should you need to resize the canvas use the
setSizemethod so that it accurately updates all of the underlying texture data as well. Forgetting to do this (i.e. by changing the canvas size directly from your code) could cause graphical errors.