Create
Class: Phaser.Create
Constructor
new Create(game)
The Phaser.Create class is a collection of smaller helper methods that allow you to generate game content
quickly and easily, without the need for any external files. You can create textures for sprites and in
coming releases we'll add dynamic sound effect generation support as well (like sfxr).
Access this via Game.create
(this.game.create
from within a State object)
Parameters
Name | Type | Description |
---|---|---|
game | Phaser.Game | Game reference to the currently running game. |
- Source code: core/Create.js (Line 18)
Public Properties
- Source code: core/Create.js (Line 58)
- Source code: core/Create.js (Line 79)
- Source code: core/Create.js (Line 72)
- Source code: core/Create.js (Line 86)
- Source code: core/Create.js (Line 65)
- Source code: core/Create.js (Line 28)
- Source code: core/Create.js (Line 33)
- Source code: core/Create.js (Line 38)
- Source code: core/Create.js (Line 23)
- Source code: core/Create.js (Line 43)
[static] PALETTE_ARNE : number
A 16 color palette by Arne
[static] PALETTE_C64 : number
A 16 color C64 inspired palette.
[static] PALETTE_CGA : number
A 16 color CGA inspired palette.
[static] PALETTE_JAPANESE_MACHINE : number
A 16 color palette inspired by Japanese computers like the MSX.
[static] PALETTE_JMP : number
A 16 color JMP inspired palette.
bmd : Phaser.BitmapData
The internal BitmapData Create uses to generate textures from.
canvas :HTMLCanvasElement
The canvas the BitmapData uses.
ctx
Properties:
Name | Type | Description |
---|---|---|
context | CanvasRenderingContext2D | The 2d context of the canvas. |
game : Phaser.Game
A reference to the currently running Game.
palettes :array
A range of 16 color palettes for use with sprite generation.
Public Methods
- Source code: core/Create.js (Line 162)
- Source code: core/Create.js (Line 90)
grid(key, width, height, cellWidth, cellHeight, color) → {PIXI.Texture}
Creates a grid texture based on the given dimensions.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key used to store this texture in the Phaser Cache. |
width | integer | The width of the grid in pixels. |
height | integer | The height of the grid in pixels. |
cellWidth | integer | The width of the grid cells in pixels. |
cellHeight | integer | The height of the grid cells in pixels. |
color | string | The color to draw the grid lines in. Should be a Canvas supported color string like |
Returns
The newly generated 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.
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.Create.html