Skip to content

Commit 53aa435

Browse files
committed
Updated DynamicTexture.setPixel, added GameMath.shuffleArray, fixed Animation.frame and created a few new tests
1 parent 5556859 commit 53aa435

21 files changed

Lines changed: 529 additions & 95 deletions

Phaser/AnimationManager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ module Phaser {
8686
* @param frameRate {number} The speed in frames per second that the animation should play at (e.g. 60 fps).
8787
* @param loop {boolean} Whether or not the animation is looped or just plays once.
8888
* @param useNumericIndex {boolean} Use number indexes instead of string indexes?
89+
* @return {Animation} The Animation that was created
8990
*/
90-
public add(name: string, frames: any[] = null, frameRate: number = 60, loop: bool = false, useNumericIndex: bool = true) {
91+
public add(name: string, frames: any[] = null, frameRate: number = 60, loop: bool = false, useNumericIndex: bool = true): Animation {
9192

9293
if (this._frameData == null)
9394
{
@@ -117,6 +118,8 @@ module Phaser {
117118
this.currentAnim = this._anims[name];
118119
this.currentFrame = this.currentAnim.currentFrame;
119120

121+
return this._anims[name];
122+
120123
}
121124

122125
/**

Phaser/DynamicTexture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module Phaser {
117117
* @param y {number} Y position of the target pixel.
118118
* @param color {number} Native integer with color value. (format: 0xRRGGBB)
119119
*/
120-
public setPixel(x: number, y: number, color: number) {
120+
public setPixel(x: number, y: number, color: string) {
121121

122122
this.context.fillStyle = color;
123123
this.context.fillRect(x, y, 1, 1);

Phaser/Game.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ module Phaser {
470470
this.onDestroyCallback.call(this.callbackContext);
471471
}
472472

473-
this.input.reset();
473+
this.input.reset(true);
474474

475475
// Prototype?
476476
if (typeof state === 'function')

Phaser/GameMath.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,24 @@ module Phaser {
10031003
return ax * bx + ay * by;
10041004
}
10051005

1006+
/**
1007+
* Shuffles the data in the given array into a new order
1008+
* @param array The array to shuffle
1009+
* @return The array
1010+
*/
1011+
public shuffleArray(array) {
1012+
1013+
for (var i = array.length - 1; i > 0; i--)
1014+
{
1015+
var j = Math.floor(Math.random() * (i + 1));
1016+
var temp = array[i];
1017+
array[i] = array[j];
1018+
array[j] = temp;
1019+
}
1020+
1021+
return array;
1022+
1023+
}
10061024

10071025
}
10081026

Phaser/Stage.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ module Phaser {
2929
this._game = game;
3030

3131
this.canvas = <HTMLCanvasElement> document.createElement('canvas');
32-
this.canvas.id = 'bob';
3332
this.canvas.width = width;
3433
this.canvas.height = height;
3534

@@ -212,6 +211,9 @@ module Phaser {
212211

213212
}
214213

214+
/**
215+
* Get the DOM offset values of the given element
216+
*/
215217
private getOffset(element): MicroPoint {
216218

217219
var box = element.getBoundingClientRect();

Phaser/gameobjects/GeomSprite.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ module Phaser {
120120
public lineColor: string = 'rgb(0,255,0)';
121121

122122
/**
123-
* Width of outline. (default is 1)
124-
* @type {number}
123+
* The color of the filled area in rgb or rgba string format
124+
* @type {string} Defaults to rgb(0,100,0) - a green color
125125
*/
126126
public fillColor: string = 'rgb(0,100,0)';
127127

@@ -341,13 +341,6 @@ module Phaser {
341341
this._dw = this.bounds.width * this.scale.x;
342342
this._dh = this.bounds.height * this.scale.y;
343343

344-
// Circles are drawn center based
345-
if (this.type == GeomSprite.CIRCLE)
346-
{
347-
this._dx += this.circle.radius;
348-
this._dy += this.circle.radius;
349-
}
350-
351344
// Apply camera difference
352345
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
353346
{
@@ -391,7 +384,11 @@ module Phaser {
391384
{
392385
this.context.beginPath();
393386
this.context.arc(this._dx, this._dy, this.circle.radius, 0, Math.PI * 2);
394-
this.context.stroke();
387+
388+
if (this.renderOutline)
389+
{
390+
this.context.stroke();
391+
}
395392

396393
if (this.renderFill)
397394
{

Phaser/gameobjects/Sprite.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module Phaser {
3333

3434
if (key !== null)
3535
{
36+
this.cacheKey = key;
3637
this.loadGraphic(key);
3738
}
3839
else
@@ -70,6 +71,11 @@ module Phaser {
7071
*/
7172
public animations: AnimationManager;
7273

74+
/**
75+
* The cache key that was used for this texture (if any)
76+
*/
77+
public cacheKey: string;
78+
7379
/**
7480
* Render bound of this sprite for debugging? (default to false)
7581
* @type {boolean}
@@ -95,7 +101,7 @@ module Phaser {
95101
public renderDebugPointColor: string = 'rgba(255,255,255,1)';
96102

97103
/**
98-
* Flip the graphic vertically? (default to false)
104+
* Flip the graphic horizontally? (defaults to false)
99105
* @type {boolean}
100106
*/
101107
public flipped: bool = false;

Phaser/system/Device.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,27 @@ module Phaser {
470470

471471
}
472472

473+
public isConsoleOpen(): bool {
474+
475+
if (window.console && window.console['firebug'])
476+
{
477+
return true;
478+
}
479+
480+
if (window.console)
481+
{
482+
console.profile();
483+
console.profileEnd();
484+
485+
if (console.clear) console.clear();
486+
487+
return console['profiles'].length > 0;
488+
}
489+
490+
return false;
491+
492+
}
493+
473494
/**
474495
* Get all informations of host device.
475496
* @return {string} Informations in a string.

Phaser/system/Tween.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@ module Phaser {
114114
public onComplete: Phaser.Signal;
115115

116116
/**
117-
* Config the tween result.
117+
* Configure the Tween
118118
* @param properties {object} Propertis you want to tween.
119119
* @param [duration] {number} duration of this tween.
120-
* @param ease {any} Easing function.
121-
* @param autoStart {boolean} Whether this tween will start automatically or not.
120+
* @param [ease] {any} Easing function.
121+
* @param [autoStart] {boolean} Whether this tween will start automatically or not.
122+
* @param [delay] {number} delay before this tween will start, defaults to 0 (no delay)
122123
* @return {Tween} Itself.
123124
*/
124-
public to(properties, duration?: number = 1000, ease?: any = null, autoStart?: bool = false) {
125+
public to(properties, duration?: number = 1000, ease?: any = null, autoStart?: bool = false, delay?:number = 0) {
125126

126127
this._duration = duration;
127128

@@ -133,6 +134,11 @@ module Phaser {
133134
this._easingFunction = ease;
134135
}
135136

137+
if (delay > 0)
138+
{
139+
this._delayTime = delay;
140+
}
141+
136142
if (autoStart === true)
137143
{
138144
return this.start();

Phaser/system/animation/Animation.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,25 @@ module Phaser {
4444
* Local private reference to game.
4545
*/
4646
private _game: Game;
47+
4748
/**
4849
* Local private reference to its owner sprite.
4950
* @type {Sprite}
5051
*/
5152
private _parent: Sprite;
53+
5254
/**
5355
* Animation frame container.
5456
* @type {number[]}
5557
*/
5658
private _frames: number[];
59+
5760
/**
5861
* Frame data of this animation.(parsed from sprite sheet)
5962
* @type {FrameData}
6063
*/
6164
private _frameData: FrameData;
65+
6266
/**
6367
* Index of current frame.
6468
* @type {number}
@@ -70,6 +74,7 @@ module Phaser {
7074
* @type number
7175
*/
7276
private _timeLastFrame: number;
77+
7378
/**
7479
* Time when this will switch to next frame (in ms).
7580
* @type number
@@ -81,6 +86,7 @@ module Phaser {
8186
* @type {string}
8287
*/
8388
public name: string;
89+
8490
/**
8591
* Currently played frame instance.
8692
* @type {Frame}
@@ -92,16 +98,19 @@ module Phaser {
9298
* @type {boolean}
9399
*/
94100
public isFinished: bool;
101+
95102
/**
96103
* Whethor or not this animation is currently playing.
97104
* @type {boolean}
98105
*/
99106
public isPlaying: bool;
107+
100108
/**
101109
* Whether or not the animation is looped.
102110
* @type {boolean}
103111
*/
104112
public looped: bool;
113+
105114
/**
106115
* Time between frames in ms.
107116
* @type {number}
@@ -113,7 +122,16 @@ module Phaser {
113122
}
114123

115124
public get frame(): number {
116-
return this._frameIndex;
125+
126+
if (this.currentFrame !== null)
127+
{
128+
return this.currentFrame.index;
129+
}
130+
else
131+
{
132+
return this._frameIndex;
133+
}
134+
117135
}
118136

119137
public set frame(value: number) {

0 commit comments

Comments
 (0)