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:
- src/core/Create.js line 18
Members
-
<static, constant> PALETTE_ARNE : number
-
A 16 color palette by Arne
Type:
- number
- Source:
- src/core/Create.js line 57
-
<static, constant> PALETTE_C64 : number
-
A 16 color C64 inspired palette.
Type:
- number
- Source:
- src/core/Create.js line 78
-
<static, constant> PALETTE_CGA : number
-
A 16 color CGA inspired palette.
Type:
- number
- Source:
- src/core/Create.js line 71
-
<static, constant> PALETTE_JAPANESE_MACHINE : number
-
A 16 color palette inspired by Japanese computers like the MSX.
Type:
- number
- Source:
- src/core/Create.js line 85
-
<static, constant> PALETTE_JMP : number
-
A 16 color JMP inspired palette.
Type:
- number
- Source:
- src/core/Create.js line 64
-
bmd : Phaser.BitmapData
-
The internal BitmapData Create uses to generate textures from.
Type:
- Source:
- src/core/Create.js line 28
-
canvas : HTMLCanvasElement
-
The canvas the BitmapData uses.
Type:
- HTMLCanvasElement
- Source:
- src/core/Create.js line 33
-
ctx
-
- Source:
- src/core/Create.js line 38
Properties:
Name Type Description contextCanvasRenderingContext2D The 2d context of the canvas.
-
game : Phaser.Game
-
A reference to the currently running Game.
Type:
- Source:
- src/core/Create.js line 23
-
palettes : array
-
A range of 16 color palettes for use with sprite generation.
Type:
- array
- Source:
- src/core/Create.js line 43
Methods
-
copy( [dest] [, x] [, y] [, width] [, height] [, blendMode] [, roundPx])
-
Copies the contents of Create's canvas to the given BitmapData object, or a new BitmapData object.
Parameters:
Name Type Argument Default Description destPhaser.BitmapData <optional>
The BitmapData receiving the copied image.
xnumber <optional>
0 The x coordinate to translate to before drawing.
ynumber <optional>
0 The y coordinate to translate to before drawing.
widthnumber <optional>
The new width of the Sprite being copied.
heightnumber <optional>
The new height of the Sprite being copied.
blendModestring <optional>
null The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'.
roundPxboolean <optional>
false Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances.
- Source:
- src/core/Create.js line 228
Returns:
- The
destargument (if passed), or a new BitmapData object
- Type
- Phaser.BitmapData
-
grid(key, width, height, cellWidth, cellHeight, color [, generateTexture] [, callback] [, callbackContext])
-
Creates a grid texture based on the given dimensions.
Use Phaser.Loader#imageFromGrid to preload an image of the same.
Parameters:
Name Type Argument Default Description keystring The key used to store this texture in the Phaser Cache.
widthinteger The width of the grid in pixels.
heightinteger The height of the grid in pixels.
cellWidthinteger The width of the grid cells in pixels.
cellHeightinteger The height of the grid cells in pixels.
colorstring The color to draw the grid lines in. Should be a Canvas supported color string like
#ff5500orrgba(200,50,3,0.5).generateTextureboolean <optional>
true When false, a new BitmapData object is returned instead.
callbackfunction <optional>
A function to execute once the texture is generated. It will be passed the newly generated texture.
callbackContextany <optional>
The context in which to invoke the callback.
- Source:
- src/core/Create.js line 168
Returns:
The newly generated texture, or a new BitmapData object if
generateTextureis false, ornullif a callback was passed and the texture isn't available yet.- Type
- PIXI.Texture | Phaser.BitmapData
-
texture(key, data [, pixelWidth] [, pixelHeight] [, palette] [, generateTexture] [, callback] [, callbackContext])
-
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');Use Phaser.Loader#imageFromTexture to preload an image of the same.
Parameters:
Name Type Argument Default Description keystring The key used to store this texture in the Phaser Cache.
dataarray An array of pixel data.
pixelWidthinteger <optional>
8 The width of each pixel.
pixelHeightinteger <optional>
8 The height of each pixel.
paletteinteger <optional>
0 The palette to use when rendering the texture. One of the Phaser.Create.PALETTE consts.
generateTextureboolean <optional>
true When false, a new BitmapData object is returned instead.
callbackfunction <optional>
A function to execute once the texture is generated. It will be passed the newly generated texture.
callbackContextany <optional>
The context in which to invoke the callback.
- Source:
- src/core/Create.js line 89
Returns:
The newly generated texture, or a new BitmapData object if
generateTextureis false, ornullif a callback was passed and the texture isn't available yet.- Type
- PIXI.Texture | Phaser.BitmapData