Skip to content

Commit e41e35f

Browse files
committed
Fixed an error that stopped 2 tweens from being able to run on the same object. Also refactored a lot of the classes to remove prototype properties and move them to local instance properties.
1 parent a486bf6 commit e41e35f

23 files changed

Lines changed: 468 additions & 493 deletions

examples/a_template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
(function () {
1414

15-
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, render: render });
15+
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
1616

1717
function preload() {
1818

examples/tween2.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a new beginning</title>
5+
<?php
6+
require('js.php');
7+
?>
8+
</head>
9+
<body>
10+
11+
<script type="text/javascript">
12+
13+
(function () {
14+
15+
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
16+
17+
function preload() {
18+
19+
game.load.image('atari1', 'assets/sprites/atari130xe.png');
20+
21+
}
22+
23+
function create() {
24+
25+
var tempSprite = game.add.sprite(0, 0, 'atari1');
26+
27+
game.add.tween(tempSprite).to({ x: 600 }, 4000, Phaser.Easing.Linear.None, true);
28+
game.add.tween(tempSprite).to({ y: 500 }, 4000, Phaser.Easing.Linear.None, true);
29+
30+
}
31+
32+
function update() {
33+
}
34+
35+
function render() {
36+
}
37+
38+
})();
39+
</script>
40+
41+
</body>
42+
</html>

src/animation/Animation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Phaser.Animation.prototype = {
6565

6666
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
6767
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
68-
// this._parent.events.onAnimationStart.dispatch(this._parent, this);
68+
this._parent.events.onAnimationStart.dispatch(this._parent, this);
6969

7070
return this;
7171

@@ -114,7 +114,7 @@ Phaser.Animation.prototype = {
114114
this._frameIndex = 0;
115115
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
116116
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
117-
// this._parent.events.onAnimationLoop.dispatch(this._parent, this);
117+
this._parent.events.onAnimationLoop.dispatch(this._parent, this);
118118
}
119119
else
120120
{
@@ -158,7 +158,7 @@ Phaser.Animation.prototype = {
158158

159159
this.isPlaying = false;
160160
this.isFinished = true;
161-
// this._parent.events.onAnimationComplete.dispatch(this._parent, this);
161+
this._parent.events.onAnimationComplete.dispatch(this._parent, this);
162162

163163
}
164164

src/animation/AnimationManager.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @copyright 2013 Photon Storm Ltd.
1010
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
1111
*/
12-
Phaser.AnimationManager = function (parent) {
12+
Phaser.AnimationManager = function (sprite) {
1313

1414
/**
1515
* Data contains animation frames.
@@ -22,17 +22,18 @@ Phaser.AnimationManager = function (parent) {
2222
*/
2323
this.currentFrame = null;
2424

25-
this._parent = parent;
25+
this.sprite = sprite;
2626

27-
this.game = parent.game;
27+
this.game = sprite.game;
2828

2929
this._anims = {};
3030

31+
this.updateIfVisible = true;
32+
3133
};
3234

3335
Phaser.AnimationManager.prototype = {
3436

35-
updateIfVisible: true,
3637

3738
/**
3839
* Load animation frame data.
@@ -68,12 +69,12 @@ Phaser.AnimationManager.prototype = {
6869
}
6970

7071
// Create the signals the AnimationManager will emit
71-
// if (this._parent.events.onAnimationStart == null)
72-
// {
73-
// this._parent.events.onAnimationStart = new Phaser.Signal();
74-
// this._parent.events.onAnimationComplete = new Phaser.Signal();
75-
// this._parent.events.onAnimationLoop = new Phaser.Signal();
76-
// }
72+
if (this.sprite.events.onAnimationStart == null)
73+
{
74+
this.sprite.events.onAnimationStart = new Phaser.Signal();
75+
this.sprite.events.onAnimationComplete = new Phaser.Signal();
76+
this.sprite.events.onAnimationLoop = new Phaser.Signal();
77+
}
7778

7879
if (frames == null)
7980
{
@@ -93,10 +94,10 @@ Phaser.AnimationManager.prototype = {
9394
frames = this._frameData.getFrameIndexesByName(frames);
9495
}
9596

96-
this._anims[name] = new Phaser.Animation(this.game, this._parent, this._frameData, name, frames, frameRate, loop);
97+
this._anims[name] = new Phaser.Animation(this.game, this.sprite, this._frameData, name, frames, frameRate, loop);
9798
this.currentAnim = this._anims[name];
9899
this.currentFrame = this.currentAnim.currentFrame;
99-
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
100+
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
100101

101102
return this._anims[name];
102103

@@ -181,15 +182,15 @@ Phaser.AnimationManager.prototype = {
181182
*/
182183
update: function () {
183184

184-
if (this.updateIfVisible && this._parent.visible == false)
185+
if (this.updateIfVisible && this.sprite.visible == false)
185186
{
186187
return false;
187188
}
188189

189190
if (this.currentAnim && this.currentAnim.update() == true)
190191
{
191192
this.currentFrame = this.currentAnim.currentFrame;
192-
this._parent.currentFrame = this.currentFrame;
193+
this.sprite.currentFrame = this.currentFrame;
193194
return true;
194195
}
195196

@@ -261,8 +262,8 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
261262
{
262263
this.currentFrame = this._frameData.getFrame(value);
263264
this._frameIndex = value;
264-
this._parent.currentFrame = this.currentFrame;
265-
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
265+
this.sprite.currentFrame = this.currentFrame;
266+
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
266267
}
267268

268269
},
@@ -288,8 +289,8 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", {
288289
{
289290
this.currentFrame = this._frameData.getFrameByName(value);
290291
this._frameIndex = this.currentFrame.index;
291-
this._parent.currentFrame = this.currentFrame;
292-
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
292+
this.sprite.currentFrame = this.currentFrame;
293+
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
293294
}
294295
else
295296
{

src/animation/Frame.js

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,133 +10,119 @@
1010
*/
1111
Phaser.Animation.Frame = function (x, y, width, height, name, uuid) {
1212

13-
this.x = x;
14-
this.y = y;
15-
this.width = width;
16-
this.height = height;
17-
this.sourceSizeW = width;
18-
this.sourceSizeH = height;
19-
this.centerX = Math.floor(width / 2);
20-
this.centerY = Math.floor(height / 2);
21-
this.name = name;
22-
this.uuid = uuid;
23-
this.distance = Phaser.Math.distance(0, 0, width, height);
24-
25-
};
26-
27-
Phaser.Animation.Frame.prototype = {
28-
29-
/**
30-
* A link to the PIXI.TextureCache entry
31-
*/
32-
uuid: '',
33-
3413
/**
3514
* X position within the image to cut from.
3615
* @type {number}
3716
*/
38-
x: 0,
17+
this.x = x;
3918

4019
/**
4120
* Y position within the image to cut from.
4221
* @type {number}
4322
*/
44-
y: 0,
23+
this.y = y;
4524

4625
/**
4726
* Width of the frame.
4827
* @type {number}
4928
*/
50-
width: 0,
29+
this.width = width;
5130

5231
/**
5332
* Height of the frame.
5433
* @type {number}
5534
*/
56-
height: 0,
35+
this.height = height;
5736

5837
/**
5938
* center X position within the image to cut from.
6039
* @type {number}
6140
*/
62-
centerX: 0,
41+
this.centerX = Math.floor(width / 2);
6342

6443
/**
6544
* center Y position within the image to cut from.
6645
* @type {number}
6746
*/
68-
centerY: 0,
47+
this.centerY = Math.floor(height / 2);
6948

7049
/**
71-
* The distance from the top left to the bottom-right of this Frame.
50+
* Useful for Sprite Sheets.
7251
* @type {number}
7352
*/
74-
distance: 0,
53+
this.index = 0;
7554

7655
/**
77-
* Useful for Sprite Sheets.
78-
* @type {number}
56+
* Useful for Texture Atlas files. (is set to the filename value)
7957
*/
80-
index: 0,
58+
this.name = name;
8159

8260
/**
83-
* Useful for Texture Atlas files. (is set to the filename value)
61+
* A link to the PIXI.TextureCache entry
62+
*/
63+
this.uuid = uuid;
64+
65+
/**
66+
* The distance from the top left to the bottom-right of this Frame.
67+
* @type {number}
8468
*/
85-
name: '',
69+
this.distance = Phaser.Math.distance(0, 0, width, height);
8670

8771
/**
8872
* Rotated? (not yet implemented)
8973
*/
90-
rotated: false,
74+
this.rotated = false;
9175

9276
/**
9377
* Either cw or ccw, rotation is always 90 degrees.
9478
*/
95-
rotationDirection: 'cw',
79+
this.rotationDirection = 'cw';
9680

9781
/**
9882
* Was it trimmed when packed?
9983
* @type {bool}
10084
*/
101-
trimmed: false,
102-
103-
// The coordinates of the trimmed sprite inside the original sprite
85+
this.trimmed = false;
10486

10587
/**
10688
* Width of the original sprite.
10789
* @type {number}
10890
*/
109-
sourceSizeW: 0,
91+
this.sourceSizeW = width;
11092

11193
/**
11294
* Height of the original sprite.
11395
* @type {number}
11496
*/
115-
sourceSizeH: 0,
97+
this.sourceSizeH = height;
11698

11799
/**
118100
* X position of the trimmed sprite inside original sprite.
119101
* @type {number}
120102
*/
121-
spriteSourceSizeX: 0,
103+
this.spriteSourceSizeX = 0;
122104

123105
/**
124106
* Y position of the trimmed sprite inside original sprite.
125107
* @type {number}
126108
*/
127-
spriteSourceSizeY: 0,
109+
this.spriteSourceSizeY = 0;
128110

129111
/**
130112
* Width of the trimmed sprite.
131113
* @type {number}
132114
*/
133-
spriteSourceSizeW: 0,
115+
this.spriteSourceSizeW = 0;
134116

135117
/**
136118
* Height of the trimmed sprite.
137119
* @type {number}
138120
*/
139-
spriteSourceSizeH: 0,
121+
this.spriteSourceSizeH = 0;
122+
123+
};
124+
125+
Phaser.Animation.Frame.prototype = {
140126

141127
/**
142128
* Set trim of the frame.

0 commit comments

Comments
 (0)