mirror of
https://github.com/wassname/phaser.git
synced 2026-08-09 12:20:34 +08:00
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.
This commit is contained in:
@@ -65,7 +65,7 @@ Phaser.Animation.prototype = {
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
// this._parent.events.onAnimationStart.dispatch(this._parent, this);
|
||||
this._parent.events.onAnimationStart.dispatch(this._parent, this);
|
||||
|
||||
return this;
|
||||
|
||||
@@ -114,7 +114,7 @@ Phaser.Animation.prototype = {
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
// this._parent.events.onAnimationLoop.dispatch(this._parent, this);
|
||||
this._parent.events.onAnimationLoop.dispatch(this._parent, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -158,7 +158,7 @@ Phaser.Animation.prototype = {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
// this._parent.events.onAnimationComplete.dispatch(this._parent, this);
|
||||
this._parent.events.onAnimationComplete.dispatch(this._parent, this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
Phaser.AnimationManager = function (parent) {
|
||||
Phaser.AnimationManager = function (sprite) {
|
||||
|
||||
/**
|
||||
* Data contains animation frames.
|
||||
@@ -22,17 +22,18 @@ Phaser.AnimationManager = function (parent) {
|
||||
*/
|
||||
this.currentFrame = null;
|
||||
|
||||
this._parent = parent;
|
||||
this.sprite = sprite;
|
||||
|
||||
this.game = parent.game;
|
||||
this.game = sprite.game;
|
||||
|
||||
this._anims = {};
|
||||
|
||||
this.updateIfVisible = true;
|
||||
|
||||
};
|
||||
|
||||
Phaser.AnimationManager.prototype = {
|
||||
|
||||
updateIfVisible: true,
|
||||
|
||||
/**
|
||||
* Load animation frame data.
|
||||
@@ -68,12 +69,12 @@ Phaser.AnimationManager.prototype = {
|
||||
}
|
||||
|
||||
// Create the signals the AnimationManager will emit
|
||||
// if (this._parent.events.onAnimationStart == null)
|
||||
// {
|
||||
// this._parent.events.onAnimationStart = new Phaser.Signal();
|
||||
// this._parent.events.onAnimationComplete = new Phaser.Signal();
|
||||
// this._parent.events.onAnimationLoop = new Phaser.Signal();
|
||||
// }
|
||||
if (this.sprite.events.onAnimationStart == null)
|
||||
{
|
||||
this.sprite.events.onAnimationStart = new Phaser.Signal();
|
||||
this.sprite.events.onAnimationComplete = new Phaser.Signal();
|
||||
this.sprite.events.onAnimationLoop = new Phaser.Signal();
|
||||
}
|
||||
|
||||
if (frames == null)
|
||||
{
|
||||
@@ -93,10 +94,10 @@ Phaser.AnimationManager.prototype = {
|
||||
frames = this._frameData.getFrameIndexesByName(frames);
|
||||
}
|
||||
|
||||
this._anims[name] = new Phaser.Animation(this.game, this._parent, this._frameData, name, frames, frameRate, loop);
|
||||
this._anims[name] = new Phaser.Animation(this.game, this.sprite, this._frameData, name, frames, frameRate, loop);
|
||||
this.currentAnim = this._anims[name];
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
|
||||
return this._anims[name];
|
||||
|
||||
@@ -181,7 +182,7 @@ Phaser.AnimationManager.prototype = {
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this.updateIfVisible && this._parent.visible == false)
|
||||
if (this.updateIfVisible && this.sprite.visible == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -189,7 +190,7 @@ Phaser.AnimationManager.prototype = {
|
||||
if (this.currentAnim && this.currentAnim.update() == true)
|
||||
{
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
this._parent.currentFrame = this.currentFrame;
|
||||
this.sprite.currentFrame = this.currentFrame;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -261,8 +262,8 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
|
||||
{
|
||||
this.currentFrame = this._frameData.getFrame(value);
|
||||
this._frameIndex = value;
|
||||
this._parent.currentFrame = this.currentFrame;
|
||||
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
this.sprite.currentFrame = this.currentFrame;
|
||||
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
}
|
||||
|
||||
},
|
||||
@@ -288,8 +289,8 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", {
|
||||
{
|
||||
this.currentFrame = this._frameData.getFrameByName(value);
|
||||
this._frameIndex = this.currentFrame.index;
|
||||
this._parent.currentFrame = this.currentFrame;
|
||||
this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
this.sprite.currentFrame = this.currentFrame;
|
||||
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+32
-46
@@ -10,133 +10,119 @@
|
||||
*/
|
||||
Phaser.Animation.Frame = function (x, y, width, height, name, uuid) {
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.sourceSizeW = width;
|
||||
this.sourceSizeH = height;
|
||||
this.centerX = Math.floor(width / 2);
|
||||
this.centerY = Math.floor(height / 2);
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
this.distance = Phaser.Math.distance(0, 0, width, height);
|
||||
|
||||
};
|
||||
|
||||
Phaser.Animation.Frame.prototype = {
|
||||
|
||||
/**
|
||||
* A link to the PIXI.TextureCache entry
|
||||
*/
|
||||
uuid: '',
|
||||
|
||||
/**
|
||||
* X position within the image to cut from.
|
||||
* @type {number}
|
||||
*/
|
||||
x: 0,
|
||||
this.x = x;
|
||||
|
||||
/**
|
||||
* Y position within the image to cut from.
|
||||
* @type {number}
|
||||
*/
|
||||
y: 0,
|
||||
this.y = y;
|
||||
|
||||
/**
|
||||
* Width of the frame.
|
||||
* @type {number}
|
||||
*/
|
||||
width: 0,
|
||||
this.width = width;
|
||||
|
||||
/**
|
||||
* Height of the frame.
|
||||
* @type {number}
|
||||
*/
|
||||
height: 0,
|
||||
this.height = height;
|
||||
|
||||
/**
|
||||
* center X position within the image to cut from.
|
||||
* @type {number}
|
||||
*/
|
||||
centerX: 0,
|
||||
this.centerX = Math.floor(width / 2);
|
||||
|
||||
/**
|
||||
* center Y position within the image to cut from.
|
||||
* @type {number}
|
||||
*/
|
||||
centerY: 0,
|
||||
|
||||
/**
|
||||
* The distance from the top left to the bottom-right of this Frame.
|
||||
* @type {number}
|
||||
*/
|
||||
distance: 0,
|
||||
this.centerY = Math.floor(height / 2);
|
||||
|
||||
/**
|
||||
* Useful for Sprite Sheets.
|
||||
* @type {number}
|
||||
*/
|
||||
index: 0,
|
||||
this.index = 0;
|
||||
|
||||
/**
|
||||
* Useful for Texture Atlas files. (is set to the filename value)
|
||||
*/
|
||||
name: '',
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* A link to the PIXI.TextureCache entry
|
||||
*/
|
||||
this.uuid = uuid;
|
||||
|
||||
/**
|
||||
* The distance from the top left to the bottom-right of this Frame.
|
||||
* @type {number}
|
||||
*/
|
||||
this.distance = Phaser.Math.distance(0, 0, width, height);
|
||||
|
||||
/**
|
||||
* Rotated? (not yet implemented)
|
||||
*/
|
||||
rotated: false,
|
||||
this.rotated = false;
|
||||
|
||||
/**
|
||||
* Either cw or ccw, rotation is always 90 degrees.
|
||||
*/
|
||||
rotationDirection: 'cw',
|
||||
this.rotationDirection = 'cw';
|
||||
|
||||
/**
|
||||
* Was it trimmed when packed?
|
||||
* @type {bool}
|
||||
*/
|
||||
trimmed: false,
|
||||
|
||||
// The coordinates of the trimmed sprite inside the original sprite
|
||||
this.trimmed = false;
|
||||
|
||||
/**
|
||||
* Width of the original sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
sourceSizeW: 0,
|
||||
this.sourceSizeW = width;
|
||||
|
||||
/**
|
||||
* Height of the original sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
sourceSizeH: 0,
|
||||
this.sourceSizeH = height;
|
||||
|
||||
/**
|
||||
* X position of the trimmed sprite inside original sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
spriteSourceSizeX: 0,
|
||||
this.spriteSourceSizeX = 0;
|
||||
|
||||
/**
|
||||
* Y position of the trimmed sprite inside original sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
spriteSourceSizeY: 0,
|
||||
this.spriteSourceSizeY = 0;
|
||||
|
||||
/**
|
||||
* Width of the trimmed sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
spriteSourceSizeW: 0,
|
||||
this.spriteSourceSizeW = 0;
|
||||
|
||||
/**
|
||||
* Height of the trimmed sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
spriteSourceSizeH: 0,
|
||||
this.spriteSourceSizeH = 0;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Animation.Frame.prototype = {
|
||||
|
||||
/**
|
||||
* Set trim of the frame.
|
||||
|
||||
+18
-17
@@ -10,26 +10,23 @@
|
||||
*/
|
||||
Phaser.Animation.FrameData = function () {
|
||||
|
||||
/**
|
||||
* Local frame container.
|
||||
* @type {Phaser.Frame[]}
|
||||
* @private
|
||||
*/
|
||||
this._frames = [];
|
||||
|
||||
/**
|
||||
* Local frameName<->index container.
|
||||
* @private
|
||||
*/
|
||||
this._frameNames = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.Animation.FrameData.prototype = {
|
||||
|
||||
/**
|
||||
* Local frame container.
|
||||
* @type {Phaser.Frame[]}
|
||||
* @private
|
||||
*/
|
||||
_frames: [],
|
||||
|
||||
/**
|
||||
* Local frameName<->index container.
|
||||
* @private
|
||||
*/
|
||||
_frameNames: [],
|
||||
|
||||
/**
|
||||
* Add a new frame.
|
||||
* @param frame {Frame} The frame you want to add.
|
||||
@@ -41,7 +38,8 @@ Phaser.Animation.FrameData.prototype = {
|
||||
|
||||
this._frames.push(frame);
|
||||
|
||||
if (frame.name !== '') {
|
||||
if (frame.name !== '')
|
||||
{
|
||||
this._frameNames[frame.name] = frame.index;
|
||||
}
|
||||
|
||||
@@ -56,7 +54,8 @@ Phaser.Animation.FrameData.prototype = {
|
||||
*/
|
||||
getFrame: function (index) {
|
||||
|
||||
if (this._frames[index]) {
|
||||
if (this._frames[index])
|
||||
{
|
||||
return this._frames[index];
|
||||
}
|
||||
|
||||
@@ -71,7 +70,8 @@ Phaser.Animation.FrameData.prototype = {
|
||||
*/
|
||||
getFrameByName: function (name) {
|
||||
|
||||
if (this._frameNames[name] !== '') {
|
||||
if (this._frameNames[name] !== '')
|
||||
{
|
||||
return this._frames[this._frameNames[name]];
|
||||
}
|
||||
|
||||
@@ -86,7 +86,8 @@ Phaser.Animation.FrameData.prototype = {
|
||||
*/
|
||||
checkFrameName: function (name) {
|
||||
|
||||
if (this._frameNames[name] == null) {
|
||||
if (this._frameNames[name] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user