Skip to content

Commit deb37e9

Browse files
pixelpicoseanphotonstorm
authored andcommitted
Finish document for DynamicTexture, Loader, GeomSprite, Sprite, Camera.
1 parent ca93203 commit deb37e9

5 files changed

Lines changed: 592 additions & 44 deletions

File tree

Phaser/DynamicTexture.ts

Lines changed: 96 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ module Phaser {
1313

1414
export class DynamicTexture {
1515

16+
/**
17+
* DynamicTexture constructor
18+
* Create a new <code>DynamicTexture</code>.
19+
*
20+
* @param game {Phaser.Game} Current game instance.
21+
* @param width {number} Init width of this texture.
22+
* @param height {number} Init height of this texture.
23+
*/
1624
constructor(game: Game, width: number, height: number) {
1725

1826
this._game = game;
@@ -26,6 +34,9 @@ module Phaser {
2634

2735
}
2836

37+
/**
38+
* Local private reference to game.
39+
*/
2940
private _game: Game;
3041

3142
private _sx: number = 0;
@@ -39,10 +50,28 @@ module Phaser {
3950

4051
// Input / Output nodes?
4152

53+
/**
54+
* Bound of this texture with width and height info.
55+
* @type {Rectangle}
56+
*/
4257
public bounds: Rectangle;
58+
/**
59+
* This class is actually a wrapper of canvas.
60+
* @type {HTMLCanvasElement}
61+
*/
4362
public canvas: HTMLCanvasElement;
63+
/**
64+
* Canvas context of this object.
65+
* @type {CanvasRenderingContext2D}
66+
*/
4467
public context: CanvasRenderingContext2D;
4568

69+
/**
70+
* Get a color of a specific pixel.
71+
* @param x {number} X position of the pixel in this texture.
72+
* @param y {number} Y position of the pixel in this texture.
73+
* @return {number} A native color value integer (format: 0xRRGGBB)
74+
*/
4675
public getPixel(x: number, y: number): number {
4776

4877
//r = imageData.data[0];
@@ -55,6 +84,12 @@ module Phaser {
5584

5685
}
5786

87+
/**
88+
* Get a color of a specific pixel (including alpha value).
89+
* @param x {number} X position of the pixel in this texture.
90+
* @param y {number} Y position of the pixel in this texture.
91+
* @return A native color value integer (format: 0xAARRGGBB)
92+
*/
5893
public getPixel32(x: number, y: number) {
5994

6095
var imageData = this.context.getImageData(x, y, 1, 1);
@@ -63,40 +98,69 @@ module Phaser {
6398

6499
}
65100

66-
// Returns a CanvasPixelArray
101+
/**
102+
* Get pixels in array in a specific rectangle.
103+
* @param rect {Rectangle} The specific rectangle.
104+
* @returns {array} CanvasPixelArray.
105+
*/
67106
public getPixels(rect: Rectangle) {
68107

69108
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
70109

71110
}
72111

112+
/**
113+
* Set color of a specific pixel.
114+
* @param x {number} X position of the target pixel.
115+
* @param y {number} Y position of the target pixel.
116+
* @param color {number} Native integer with color value. (format: 0xRRGGBB)
117+
*/
73118
public setPixel(x: number, y: number, color: number) {
74119

75120
this.context.fillStyle = color;
76121
this.context.fillRect(x, y, 1, 1);
77122

78123
}
79124

125+
/**
126+
* Set color (with alpha) of a specific pixel.
127+
* @param x {number} X position of the target pixel.
128+
* @param y {number} Y position of the target pixel.
129+
* @param color {number} Native integer with color value. (format: 0xAARRGGBB)
130+
*/
80131
public setPixel32(x: number, y: number, color: number) {
81132

82133
this.context.fillStyle = color;
83134
this.context.fillRect(x, y, 1, 1);
84135

85136
}
86137

138+
/**
139+
* Set image data to a specific rectangle.
140+
* @param rect {Rectangle} Target rectangle.
141+
* @param input {object} Source image data.
142+
*/
87143
public setPixels(rect: Rectangle, input) {
88144

89145
this.context.putImageData(input, rect.x, rect.y);
90146

91147
}
92148

149+
/**
150+
* Fill a given rectangle with specific color.
151+
* @param rect {Rectangle} Target rectangle you want to fill.
152+
* @param color {number} A native number with color value. (format: 0xRRGGBB)
153+
*/
93154
public fillRect(rect: Rectangle, color: number) {
94155

95156
this.context.fillStyle = color;
96157
this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
97158

98159
}
99160

161+
/**
162+
*
163+
*/
100164
public pasteImage(key: string, frame?: number = -1, destX?: number = 0, destY?: number = 0, destWidth?: number = null, destHeight?: number = null) {
101165

102166
var texture = null;
@@ -138,21 +202,27 @@ module Phaser {
138202
if (texture != null)
139203
{
140204
this.context.drawImage(
141-
texture, // Source Image
142-
this._sx, // Source X (location within the source image)
143-
this._sy, // Source Y
144-
this._sw, // Source Width
145-
this._sh, // Source Height
146-
this._dx, // Destination X (where on the canvas it'll be drawn)
147-
this._dy, // Destination Y
148-
this._dw, // Destination Width (always same as Source Width unless scaled)
149-
this._dh // Destination Height (always same as Source Height unless scaled)
205+
texture, // Source Image
206+
this._sx, // Source X (location within the source image)
207+
this._sy, // Source Y
208+
this._sw, // Source Width
209+
this._sh, // Source Height
210+
this._dx, // Destination X (where on the canvas it'll be drawn)
211+
this._dy, // Destination Y
212+
this._dw, // Destination Width (always same as Source Width unless scaled)
213+
this._dh // Destination Height (always same as Source Height unless scaled)
150214
);
151215
}
152216

153217
}
154218

155219
// TODO - Add in support for: alphaBitmapData: BitmapData = null, alphaPoint: Point = null, mergeAlpha: bool = false
220+
/**
221+
* Copy pixel from another DynamicTexture to this texture.
222+
* @param sourceTexture {DynamicTexture} Source texture object.
223+
* @param sourceRect {Rectangle} The specific region rectangle to be copied to this in the source.
224+
* @param destPoint {Point} Top-left point the target image data will be paste at.
225+
*/
156226
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point) {
157227

158228
// Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
@@ -167,6 +237,9 @@ module Phaser {
167237

168238
}
169239

240+
/**
241+
* Clear the whole canvas.
242+
*/
170243
public clear() {
171244

172245
this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
@@ -183,13 +256,13 @@ module Phaser {
183256

184257
/**
185258
* Given an alpha and 3 color values this will return an integer representation of it
186-
*
187-
* @param alpha The Alpha value (between 0 and 255)
188-
* @param red The Red channel value (between 0 and 255)
189-
* @param green The Green channel value (between 0 and 255)
190-
* @param blue The Blue channel value (between 0 and 255)
191-
*
192-
* @return A native color value integer (format: 0xAARRGGBB)
259+
*
260+
* @param alpha {number} The Alpha value (between 0 and 255)
261+
* @param red {number} The Red channel value (between 0 and 255)
262+
* @param green {number} The Green channel value (between 0 and 255)
263+
* @param blue {number} The Blue channel value (between 0 and 255)
264+
*
265+
* @return A native color value integer (format: 0xAARRGGBB)
193266
*/
194267
private getColor32(alpha: number, red: number, green: number, blue: number): number {
195268

@@ -199,12 +272,12 @@ module Phaser {
199272

200273
/**
201274
* Given 3 color values this will return an integer representation of it
202-
*
203-
* @param red The Red channel value (between 0 and 255)
204-
* @param green The Green channel value (between 0 and 255)
205-
* @param blue The Blue channel value (between 0 and 255)
206-
*
207-
* @return A native color value integer (format: 0xRRGGBB)
275+
*
276+
* @param red {number} The Red channel value (between 0 and 255)
277+
* @param green {number} The Green channel value (between 0 and 255)
278+
* @param blue {number} The Blue channel value (between 0 and 255)
279+
*
280+
* @return A native color value integer (format: 0xRRGGBB)
208281
*/
209282
private getColor(red: number, green: number, blue: number): number {
210283

0 commit comments

Comments
 (0)