Phaser API Documentation

generateTexture(key, [width], [height])


Generate a texture from this Graphics object.

If key is a string it'll generate a new texture using it and add it into the Texture Manager (assuming no key conflict happens).

If key is a Canvas it will draw the texture to that canvas context. Note that it will NOT automatically upload it to the GPU in WebGL mode.

Please understand that the texture is created via the Canvas API of the browser, therefore some Graphics features, such as fillGradientStyle, will not appear on the resulting texture, as they're unsupported by the Canvas API.


name type arguments description
key string | HTMLCanvasElement

The key to store the texture with in the Texture Manager, or a Canvas to draw to.

width number <optional>

The width of the graphics to generate.

height number <optional>

The height of the graphics to generate.


This Game Object.

Since: 3.0.0