Create#texture()

texture(key, data, pixelWidth, pixelHeight, palette) → {PIXI.Texture}

Generates a new PIXI.Texture from the given data, which can be applied to a Sprite.

This allows you to create game graphics quickly and easily, with no external files but that use actual proper images
rather than Phaser.Graphics objects, which are expensive to render and limited in scope.

Each element of the array is a string holding the pixel color values, as mapped to one of the Phaser.Create PALETTE consts.

For example:

var data = [ ' 333 ', ' 777 ', 'E333E', ' 333 ', ' 3 3 ' ];

game.create.texture('bob', data);

The above will create a new texture called bob, which will look like a little man wearing a hat. You can then use it
for sprites the same way you use any other texture: game.add.sprite(0, 0, 'bob');

Parameters
Name Type Argument Default Description
key string

The key used to store this texture in the Phaser Cache.

data array

An array of pixel data.

pixelWidth integer <optional>
8

The width of each pixel.

pixelHeight integer <optional>
8

The height of each pixel.

palette integer <optional>
0

The palette to use when rendering the texture. One of the Phaser.Create.PALETTE consts.

Returns

The newly generated texture.

Source code: core/Create.js (Line 90)
doc_phaser
2017-02-14 10:43:13
Comments
Leave a Comment

Please login to continue.