Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord
Namespace: Create
Phaser.Create
Source: src/create/index.js (Line 7)

Namespace

Methods

<static> GenerateTexture(config)
Focus
Focus

Description:

Generates a texture based on the given Create configuration object.

The texture is drawn using a fixed-size indexed palette of 16 colors, where the hex value in the data cells map to a single color. For example, if the texture config looked like this:

var star = [
  '.....828.....',
  '....72227....',
  '....82228....',
  '...7222227...',
  '2222222222222',
  '8222222222228',
  '.72222222227.',
  '..787777787..',
  '..877777778..',
  '.78778887787.',
  '.27887.78872.',
  '.787.....787.'
];

this.textures.generate('star', { data: star, pixelWidth: 4 });

Then it would generate a texture that is 52 x 48 pixels in size, because each cell of the data array represents 1 pixel multiplied by the pixelWidth value. The cell values, such as 8, maps to color number 8 in the palette. If a cell contains a period character . then it is transparent.

The default palette is Arne16, but you can specify your own using the palette property.

Parameters:

name type description
config Phaser.Types.Create.GenerateTextureConfig

The Generate Texture Configuration object.

Returns:
Description:

An HTMLCanvasElement which contains the generated texture drawn to it.

Type:
  • HTMLCanvasElement
Examples:
Since: 3.0.0
Focus
Focus