Class: RenderTexture

Phaser. RenderTexture

new RenderTexture(game [, width] [, height] [, key] [, scaleMode] [, resolution])

A RenderTexture is a special texture that allows any displayObject to be rendered to it. It allows you to take many complex objects and render them down into a single quad (on WebGL) which can then be used to texture other display objects with. A way of generating textures at run-time.

Parameters:
Name Type Argument Default Description
game Phaser.Game

Current game instance.

width number <optional>
100

The width of the render texture.

height number <optional>
100

The height of the render texture.

key string <optional>
''

The key of the RenderTexture in the Cache, if stored there.

scaleMode number <optional>
Phaser.scaleModes.DEFAULT

One of the Phaser.scaleModes consts.

resolution number <optional>
1

The resolution of the texture being generated.

Source:
src/gameobjects/RenderTexture.js line 21

Extends

Members

baseTexture : BaseTexture

The base texture object that this texture uses

Type:
  • BaseTexture
Overrides:
Source:
src/gameobjects/RenderTexture.js line 66

crop : Rectangle

This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering, irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases)

Type:
  • Rectangle
Inherited From:
Overrides:
Source:
src/pixi/textures/Texture.js line 134

frame : Rectangle

The frame specifies the region of the base texture that this texture uses

Type:
  • Rectangle
Inherited From:
Overrides:
Source:
src/pixi/textures/Texture.js line 60

game : Phaser.Game

A reference to the currently running game.

Type:
Source:
src/gameobjects/RenderTexture.js line 34

height : Number

The height of the Texture in pixels.

Type:
  • Number
Inherited From:
Overrides:
Source:
src/pixi/textures/Texture.js line 125

isTiling : Boolean

Is this a tiling texture? As used by the likes of a TilingSprite.

Type:
  • Boolean
Inherited From:
Source:
src/pixi/textures/Texture.js line 84

key : string

The key of the RenderTexture in the Cache, if stored there.

Type:
  • string
Source:
src/gameobjects/RenderTexture.js line 39

noFrame : Boolean

Does this Texture have any frame data assigned to it?

Type:
  • Boolean
Inherited From:
Source:
src/pixi/textures/Texture.js line 33

renderer : CanvasRenderer | WebGLRenderer

The renderer this RenderTexture uses. A RenderTexture can only belong to one renderer at the moment if its webGL.

Type:
  • CanvasRenderer | WebGLRenderer
Source:
src/gameobjects/RenderTexture.js line 84

requiresReTint : Boolean

This will let a renderer know that a tinted parent has updated its texture.

Type:
  • Boolean
Inherited From:
Source:
src/pixi/textures/Texture.js line 100

requiresUpdate : Boolean

This will let a renderer know that a texture has been updated (used mainly for webGL uv updates)

Type:
  • Boolean
Inherited From:
Source:
src/pixi/textures/Texture.js line 92

rotated : Boolean

A flag that controls if this frame is rotated or not. Rotation allows you to use rotated frames in texture atlas packing, it has nothing to do with Sprite rotation.

Type:
  • Boolean
Inherited From:
Source:
src/pixi/textures/Texture.js line 144

trim : Rectangle

The texture trim data.

Type:
  • Rectangle
Inherited From:
Source:
src/pixi/textures/Texture.js line 68

type : number

Base Phaser object type.

Type:
  • number
Source:
src/gameobjects/RenderTexture.js line 44

valid : Boolean

Type:
  • Boolean
Overrides:
Source:
src/gameobjects/RenderTexture.js line 107

width : Number

The width of the Texture in pixels.

Type:
  • Number
Inherited From:
Overrides:
Source:
src/pixi/textures/Texture.js line 117

Methods

clear()

Clears the RenderTexture.

Source:
src/gameobjects/RenderTexture.js line 253

destroy(destroyBase)

Destroys this texture

Parameters:
Name Type Description
destroyBase Boolean

Whether to destroy the base texture as well

Inherited From:
Source:
src/pixi/textures/Texture.js line 173

fromCanvas(canvas, scaleMode)

Helper function that creates a new a Texture based on the given canvas element.

Parameters:
Name Type Description
canvas Canvas

The canvas element source of the texture

scaleMode Number

See {{#crossLink "PIXI/scaleModes:property"}}PIXI.scaleModes{{/crossLink}} for possible values

Inherited From:
Source:
src/pixi/textures/Texture.js line 283
Returns:
Type
Texture

getBase64( [type] [, encoderOptions])

Returns a base64 encoded string of this texture. It works by calling RenderTexture.getCanvas and then running toDataURL on that.

Parameters:
Name Type Argument Description
type string <optional>

Image format.

encoderOptions number <optional>

Image quality, for lossy formats.

Source:
src/gameobjects/RenderTexture.js line 407
See:
Returns:

A base64 encoded string of the texture.

Type
String

getCanvas()

Creates a Canvas element, renders this RenderTexture to it and then returns it.

Source:
src/gameobjects/RenderTexture.js line 422
Returns:

A Canvas element with the texture rendered on.

Type
HTMLCanvasElement

getImage( [type] [, encoderOptions] [, onLoadCallback] [, onErrorCallback])

Returns an HTML Image of the texture

The image is loaded asynchronously, not right away. Use the callbacks if you need to wait for the loaded image.

Parameters:
Name Type Argument Description
type string <optional>

Image format.

encoderOptions number <optional>

Image quality, for lossy formats.

onLoadCallback function <optional>

A function to call when the image loads.

onErrorCallback function <optional>

A function to call when the image fails to load.

Source:
src/gameobjects/RenderTexture.js line 380
See:
Returns:
Type
Image

render(displayObject [, matrix] [, clear])

This function will draw the display object to the RenderTexture.

In versions of Phaser prior to 2.4.0 the second parameter was a Phaser.Point object. This is now a Matrix allowing you much more control over how the Display Object is rendered. If you need to replicate the earlier behavior please use Phaser.RenderTexture.renderXY instead.

If you wish for the displayObject to be rendered taking its current scale, rotation and translation into account then either pass null, leave it undefined or pass displayObject.worldTransform as the matrix value.

Parameters:
Name Type Argument Default Description
displayObject Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Group

The display object to render to this texture.

matrix Phaser.Matrix <optional>

Optional matrix to apply to the display object before rendering. If null or undefined it will use the worldTransform matrix of the given display object.

clear boolean <optional>
false

If true the texture will be cleared before the display object is drawn.

Source:
src/gameobjects/RenderTexture.js line 175

renderRawXY(displayObject, x, y [, clear])

This function will draw the display object to the RenderTexture at the given coordinates.

When the display object is drawn it doesn't take into account scale, rotation or translation.

If you need those then use RenderTexture.renderXY instead.

Parameters:
Name Type Argument Default Description
displayObject Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Group

The display object to render to this texture.

x number

The x position to render the object at.

y number

The y position to render the object at.

clear boolean <optional>
false

If true the texture will be cleared before the display object is drawn.

Source:
src/gameobjects/RenderTexture.js line 148

renderXY(displayObject, x, y [, clear])

This function will draw the display object to the RenderTexture at the given coordinates.

When the display object is drawn it takes into account scale and rotation.

If you don't want those then use RenderTexture.renderRawXY instead.

Parameters:
Name Type Argument Default Description
displayObject Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Group

The display object to render to this texture.

x number

The x position to render the object at.

y number

The y position to render the object at.

clear boolean <optional>
false

If true the texture will be cleared before the display object is drawn.

Source:
src/gameobjects/RenderTexture.js line 117

resize(width, height, updateBase)

Resizes the RenderTexture.

Parameters:
Name Type Description
width number

The width to resize to.

height number

The height to resize to.

updateBase boolean

Should the baseTexture.width and height values be resized as well?

Source:
src/gameobjects/RenderTexture.js line 211

setFrame(frame)

Specifies the region of the baseTexture that this texture will use.

Parameters:
Name Type Description
frame Rectangle

The frame of the texture to set it to

Inherited From:
Source:
src/pixi/textures/Texture.js line 186

phaser-ce@2.20.1 is on GitHub and NPM

Documentation generated by JSDoc 3.6.11 on 2024-10-05 using Tomorrow.