2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2013 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
* @module Phaser.Sprite
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new <code>Sprite</code>.
|
|
|
|
* @class Phaser.Sprite
|
|
|
|
* @classdesc Description of class.
|
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Game} game - Current game instance.
|
|
|
|
* @param {Description} x - Description.
|
|
|
|
* @param {Description} y - Description.
|
|
|
|
* @param {string} key - Description.
|
|
|
|
* @param {Description} frame - Description.
|
|
|
|
*/
|
2013-09-11 02:55:53 +00:00
|
|
|
Phaser.Sprite = function (game, x, y, key, frame) {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-08-31 20:50:34 +00:00
|
|
|
x = x || 0;
|
|
|
|
y = y || 0;
|
2013-09-11 02:55:53 +00:00
|
|
|
key = key || null;
|
2013-08-31 20:50:34 +00:00
|
|
|
frame = frame || null;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
this.game = game;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2013-10-01 15:39:39 +00:00
|
|
|
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
this.exists = true;
|
2013-09-06 19:20:58 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-01 15:39:39 +00:00
|
|
|
* @property {boolean} alive - This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
this.alive = true;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Description} group - Description.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
this.group = null;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {string} name - The user defined name given to this Sprite.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
this.name = '';
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Description} type - Description.
|
|
|
|
*/
|
2013-09-12 20:54:41 +00:00
|
|
|
this.type = Phaser.SPRITE;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {number} renderOrderID - Description.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
this.renderOrderID = -1;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
|
|
|
|
* The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
|
|
|
|
* @property {number} lifespan
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-10 00:26:50 +00:00
|
|
|
this.lifespan = 0;
|
|
|
|
|
2013-09-11 15:25:46 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @property {Events} events - The Signals you can subscribe to that are dispatched when certain things happen on this Sprite or its components
|
|
|
|
*/
|
2013-09-11 15:25:46 +00:00
|
|
|
this.events = new Phaser.Events(this);
|
|
|
|
|
|
|
|
/**
|
2013-10-01 15:15:45 +00:00
|
|
|
* @property {Phaser.AnimationManager} animations - This manages animations of the sprite. You can modify animations through it. (see Phaser.AnimationManager)
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-11 15:25:46 +00:00
|
|
|
this.animations = new Phaser.AnimationManager(this);
|
|
|
|
|
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @property {InputHandler} input - The Input Handler Component.
|
|
|
|
*/
|
2013-09-11 15:25:46 +00:00
|
|
|
this.input = new Phaser.InputHandler(this);
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Description} key - Description.
|
|
|
|
*/
|
2013-09-11 02:55:53 +00:00
|
|
|
this.key = key;
|
|
|
|
|
|
|
|
if (key instanceof Phaser.RenderTexture)
|
2013-09-03 05:02:47 +00:00
|
|
|
{
|
2013-09-11 02:55:53 +00:00
|
|
|
PIXI.Sprite.call(this, key);
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-09-11 02:55:53 +00:00
|
|
|
this.currentFrame = this.game.cache.getTextureFrame(key.name);
|
2013-09-03 05:02:47 +00:00
|
|
|
}
|
2013-10-11 17:18:27 +00:00
|
|
|
else if (key instanceof PIXI.Texture)
|
|
|
|
{
|
|
|
|
PIXI.Sprite.call(this, key);
|
|
|
|
|
|
|
|
this.currentFrame = frame;
|
|
|
|
}
|
2013-09-11 01:57:36 +00:00
|
|
|
else
|
|
|
|
{
|
2013-09-11 02:55:53 +00:00
|
|
|
if (key == null || this.game.cache.checkImageKey(key) == false)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2013-09-11 02:55:53 +00:00
|
|
|
key = '__default';
|
2013-09-11 01:57:36 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 02:55:53 +00:00
|
|
|
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2013-09-11 02:55:53 +00:00
|
|
|
if (this.game.cache.isSpriteSheet(key))
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2013-09-11 02:55:53 +00:00
|
|
|
this.animations.loadFrameData(this.game.cache.getFrameData(key));
|
2013-09-03 05:02:47 +00:00
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (frame !== null)
|
|
|
|
{
|
|
|
|
if (typeof frame === 'string')
|
|
|
|
{
|
|
|
|
this.frameName = frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.frame = frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-11 02:55:53 +00:00
|
|
|
this.currentFrame = this.game.cache.getFrame(key);
|
2013-09-11 01:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-10 10:09:25 +00:00
|
|
|
|
2013-09-03 14:35:40 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* The anchor sets the origin point of the texture.
|
|
|
|
* The default is 0,0 this means the textures origin is the top left
|
|
|
|
* Setting than anchor to 0.5,0.5 means the textures origin is centered
|
|
|
|
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
|
|
|
|
*
|
|
|
|
* @property {Phaser.Point} anchor
|
|
|
|
*/
|
2013-09-03 14:35:40 +00:00
|
|
|
this.anchor = new Phaser.Point();
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Description} _cropUUID - Description.
|
|
|
|
* @private
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-11 02:55:53 +00:00
|
|
|
this._cropUUID = null;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Description} _cropUUID - Description.
|
|
|
|
* @private
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-11 02:55:53 +00:00
|
|
|
this._cropRect = null;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {number} x - Description.
|
|
|
|
*/
|
2013-09-02 22:22:24 +00:00
|
|
|
this.x = x;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} y - Description.
|
|
|
|
*/
|
2013-09-02 22:22:24 +00:00
|
|
|
this.y = y;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Description} position - Description.
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
this.position.x = x;
|
|
|
|
this.position.y = y;
|
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* Should this Sprite be automatically culled if out of range of the camera?
|
|
|
|
* A culled sprite has its visible property set to 'false'.
|
|
|
|
* Note that this check doesn't look at this Sprites children, which may still be in camera range.
|
|
|
|
* So you should set autoCull to false if the Sprite will have children likely to still be in camera range.
|
|
|
|
*
|
2013-10-01 15:39:39 +00:00
|
|
|
* @property {boolean} autoCull
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2013-09-02 22:22:24 +00:00
|
|
|
this.autoCull = false;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one.
|
|
|
|
*/
|
2013-08-30 19:05:29 +00:00
|
|
|
this.scale = new Phaser.Point(1, 1);
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} _cache - A mini cache for storing all of the calculated values.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-02 22:22:24 +00:00
|
|
|
this._cache = {
|
2013-08-31 20:50:34 +00:00
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
dirty: false,
|
|
|
|
|
|
|
|
// Transform cache
|
2013-10-04 17:09:56 +00:00
|
|
|
a00: -1, a01: -1, a02: -1, a10: -1, a11: -1, a12: -1, id: -1,
|
2013-09-02 22:22:24 +00:00
|
|
|
|
2013-09-08 21:38:19 +00:00
|
|
|
// Input specific transform cache
|
2013-10-04 17:09:56 +00:00
|
|
|
i01: -1, i10: -1, idi: -1,
|
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
// Bounds check
|
|
|
|
left: null, right: null, top: null, bottom: null,
|
|
|
|
|
2013-10-04 13:41:15 +00:00
|
|
|
// The previous calculated position
|
2013-09-02 22:22:24 +00:00
|
|
|
x: -1, y: -1,
|
|
|
|
|
|
|
|
// The actual scale values based on the worldTransform
|
|
|
|
scaleX: 1, scaleY: 1,
|
|
|
|
|
|
|
|
// The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size
|
2013-09-03 14:35:40 +00:00
|
|
|
width: this.currentFrame.sourceSizeW, height: this.currentFrame.sourceSizeH,
|
|
|
|
|
|
|
|
// The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size
|
2013-09-03 16:07:05 +00:00
|
|
|
halfWidth: Math.floor(this.currentFrame.sourceSizeW / 2), halfHeight: Math.floor(this.currentFrame.sourceSizeH / 2),
|
2013-09-02 22:22:24 +00:00
|
|
|
|
2013-09-03 14:35:40 +00:00
|
|
|
// The current frame details
|
|
|
|
frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
|
2013-09-02 22:22:24 +00:00
|
|
|
|
|
|
|
boundsX: 0, boundsY: 0,
|
|
|
|
|
|
|
|
// If this sprite visible to the camera (regardless of being set to visible or not)
|
|
|
|
cameraVisible: true
|
|
|
|
|
|
|
|
};
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} offset - Corner point defaults.
|
|
|
|
*/
|
2013-09-03 14:35:40 +00:00
|
|
|
this.offset = new Phaser.Point;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} center - Description.
|
|
|
|
*/
|
2013-09-03 16:07:05 +00:00
|
|
|
this.center = new Phaser.Point(x + Math.floor(this._cache.width / 2), y + Math.floor(this._cache.height / 2));
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} topLeft - Description.
|
|
|
|
*/
|
2013-09-03 14:35:40 +00:00
|
|
|
this.topLeft = new Phaser.Point(x, y);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} topRight - Description.
|
|
|
|
*/
|
2013-09-03 14:35:40 +00:00
|
|
|
this.topRight = new Phaser.Point(x + this._cache.width, y);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} bottomRight - Description.
|
|
|
|
*/
|
2013-09-03 14:35:40 +00:00
|
|
|
this.bottomRight = new Phaser.Point(x + this._cache.width, y + this._cache.height);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} bottomLeft - Description.
|
|
|
|
*/
|
2013-09-03 14:35:40 +00:00
|
|
|
this.bottomLeft = new Phaser.Point(x, y + this._cache.height);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Rectangle} bounds - Description.
|
|
|
|
*/
|
2013-09-03 14:35:40 +00:00
|
|
|
this.bounds = new Phaser.Rectangle(x, y, this._cache.width, this._cache.height);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Physics.Arcade.Body} body - Set-up the physics body.
|
|
|
|
*/
|
2013-09-03 14:35:40 +00:00
|
|
|
this.body = new Phaser.Physics.Arcade.Body(this);
|
2013-09-01 05:21:39 +00:00
|
|
|
|
2013-10-10 08:03:38 +00:00
|
|
|
/**
|
|
|
|
* @property {number} health - Health value. Used in combination with damage() to allow for quick killing of Sprites.
|
|
|
|
*/
|
|
|
|
this.health = 1;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Description} inWorld - World bounds check.
|
|
|
|
*/
|
2013-09-09 16:01:59 +00:00
|
|
|
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} inWorldThreshold - World bounds check.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-09 16:01:59 +00:00
|
|
|
this.inWorldThreshold = 0;
|
2013-10-08 20:09:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {boolean} outOfBoundsKill - Kills this sprite as soon as it goes outside of the World bounds.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.outOfBoundsKill = false;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2013-10-01 15:39:39 +00:00
|
|
|
* @property {boolean} _outOfBoundsFired - Description.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @private
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-09 12:29:33 +00:00
|
|
|
this._outOfBoundsFired = false;
|
|
|
|
|
2013-10-07 23:58:20 +00:00
|
|
|
/**
|
|
|
|
* A Sprite that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
|
|
|
|
* @property {boolean} fixedToCamera - Fixes this Sprite to the Camera.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.fixedToCamera = false;
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
};
|
|
|
|
|
2013-09-03 05:02:47 +00:00
|
|
|
// Needed to keep the PIXI.Sprite constructor in the prototype chain (as the core pixi renderer uses an instanceof check sadly)
|
2013-08-30 03:20:14 +00:00
|
|
|
Phaser.Sprite.prototype = Object.create(PIXI.Sprite.prototype);
|
|
|
|
Phaser.Sprite.prototype.constructor = Phaser.Sprite;
|
|
|
|
|
|
|
|
/**
|
2013-10-07 21:15:19 +00:00
|
|
|
* Automatically called by World.preUpdate. You can create your own update in Objects that extend Phaser.Sprite.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method Phaser.Sprite.prototype.preUpdate
|
|
|
|
*/
|
2013-09-10 23:35:21 +00:00
|
|
|
Phaser.Sprite.prototype.preUpdate = function() {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-09-06 19:20:58 +00:00
|
|
|
if (!this.exists)
|
|
|
|
{
|
2013-09-08 12:23:21 +00:00
|
|
|
this.renderOrderID = -1;
|
2013-09-06 19:20:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-10 00:26:50 +00:00
|
|
|
if (this.lifespan > 0)
|
|
|
|
{
|
|
|
|
this.lifespan -= this.game.time.elapsed;
|
|
|
|
|
|
|
|
if (this.lifespan <= 0)
|
|
|
|
{
|
|
|
|
this.kill();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
this._cache.dirty = false;
|
2013-09-01 04:50:47 +00:00
|
|
|
|
2013-09-03 14:35:40 +00:00
|
|
|
if (this.animations.update())
|
|
|
|
{
|
|
|
|
this._cache.dirty = true;
|
|
|
|
}
|
2013-08-31 20:50:34 +00:00
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
if (this.visible)
|
|
|
|
{
|
2013-09-08 12:23:21 +00:00
|
|
|
this.renderOrderID = this.game.world.currentRenderOrderID++;
|
2013-09-20 12:55:33 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-09-23 21:23:17 +00:00
|
|
|
this.prevX = this.x;
|
|
|
|
this.prevY = this.y;
|
|
|
|
|
2013-10-04 18:00:55 +00:00
|
|
|
this.updateCache();
|
2013-10-10 08:03:38 +00:00
|
|
|
this.updateAnimation();
|
2013-10-04 17:09:56 +00:00
|
|
|
|
|
|
|
// Re-run the camera visibility check
|
2013-10-04 18:00:55 +00:00
|
|
|
if (this._cache.dirty)
|
2013-10-04 17:09:56 +00:00
|
|
|
{
|
|
|
|
this._cache.cameraVisible = Phaser.Rectangle.intersects(this.game.world.camera.screenView, this.bounds, 0);
|
|
|
|
|
|
|
|
if (this.autoCull == true)
|
|
|
|
{
|
|
|
|
// Won't get rendered but will still get its transform updated
|
|
|
|
this.renderable = this._cache.cameraVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update our physics bounds
|
2013-10-04 18:00:55 +00:00
|
|
|
if (this.body)
|
|
|
|
{
|
|
|
|
this.body.updateBounds(this.center.x, this.center.y, this._cache.scaleX, this._cache.scaleY);
|
|
|
|
}
|
2013-10-04 17:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.body)
|
|
|
|
{
|
|
|
|
this.body.preUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Phaser.Sprite.prototype.updateCache = function() {
|
|
|
|
|
2013-09-20 12:55:33 +00:00
|
|
|
// |a c tx|
|
|
|
|
// |b d ty|
|
|
|
|
// |0 0 1|
|
2013-09-02 22:22:24 +00:00
|
|
|
|
2013-10-04 18:00:55 +00:00
|
|
|
if (this.worldTransform[1] != this._cache.i01 || this.worldTransform[3] != this._cache.i10)
|
2013-09-20 12:55:33 +00:00
|
|
|
{
|
|
|
|
this._cache.a00 = this.worldTransform[0]; // scaleX a
|
|
|
|
this._cache.a01 = this.worldTransform[1]; // skewY c
|
|
|
|
this._cache.a10 = this.worldTransform[3]; // skewX b
|
|
|
|
this._cache.a11 = this.worldTransform[4]; // scaleY d
|
2013-10-04 13:41:15 +00:00
|
|
|
|
2013-10-04 18:00:55 +00:00
|
|
|
this._cache.i01 = this.worldTransform[1]; // skewY c (remains non-modified for input checks)
|
|
|
|
this._cache.i10 = this.worldTransform[3]; // skewX b (remains non-modified for input checks)
|
|
|
|
|
2013-10-04 13:41:15 +00:00
|
|
|
this._cache.scaleX = Math.sqrt((this._cache.a00 * this._cache.a00) + (this._cache.a01 * this._cache.a01)); // round this off a bit?
|
2013-09-20 12:55:33 +00:00
|
|
|
this._cache.scaleY = Math.sqrt((this._cache.a10 * this._cache.a10) + (this._cache.a11 * this._cache.a11)); // round this off a bit?
|
2013-10-04 13:41:15 +00:00
|
|
|
|
|
|
|
this._cache.a01 *= -1;
|
2013-09-20 12:55:33 +00:00
|
|
|
this._cache.a10 *= -1;
|
2013-10-04 13:41:15 +00:00
|
|
|
|
2013-09-20 12:55:33 +00:00
|
|
|
this._cache.dirty = true;
|
|
|
|
}
|
2013-09-02 22:22:24 +00:00
|
|
|
|
2013-09-20 12:55:33 +00:00
|
|
|
if (this.worldTransform[2] != this._cache.a02 || this.worldTransform[5] != this._cache.a12)
|
|
|
|
{
|
|
|
|
this._cache.a02 = this.worldTransform[2]; // translateX tx
|
|
|
|
this._cache.a12 = this.worldTransform[5]; // translateY ty
|
|
|
|
this._cache.dirty = true;
|
|
|
|
}
|
2013-09-02 22:22:24 +00:00
|
|
|
|
2013-10-10 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Phaser.Sprite.prototype.updateAnimation = function() {
|
|
|
|
|
2013-09-27 08:57:08 +00:00
|
|
|
if (this.currentFrame && this.currentFrame.uuid != this._cache.frameID)
|
2013-09-20 12:55:33 +00:00
|
|
|
{
|
|
|
|
this._cache.frameWidth = this.texture.frame.width;
|
|
|
|
this._cache.frameHeight = this.texture.frame.height;
|
|
|
|
this._cache.frameID = this.currentFrame.uuid;
|
|
|
|
this._cache.dirty = true;
|
|
|
|
}
|
2013-09-02 22:22:24 +00:00
|
|
|
|
2013-09-27 08:57:08 +00:00
|
|
|
if (this._cache.dirty && this.currentFrame)
|
2013-09-20 12:55:33 +00:00
|
|
|
{
|
|
|
|
this._cache.width = Math.floor(this.currentFrame.sourceSizeW * this._cache.scaleX);
|
|
|
|
this._cache.height = Math.floor(this.currentFrame.sourceSizeH * this._cache.scaleY);
|
|
|
|
this._cache.halfWidth = Math.floor(this._cache.width / 2);
|
|
|
|
this._cache.halfHeight = Math.floor(this._cache.height / 2);
|
2013-09-03 14:35:40 +00:00
|
|
|
|
2013-09-20 12:55:33 +00:00
|
|
|
this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
|
|
|
|
this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
|
2013-09-03 14:35:40 +00:00
|
|
|
|
2013-09-20 12:55:33 +00:00
|
|
|
this.updateBounds();
|
2013-09-02 22:22:24 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 12:55:33 +00:00
|
|
|
Phaser.Sprite.prototype.postUpdate = function() {
|
|
|
|
|
|
|
|
if (this.exists)
|
|
|
|
{
|
2013-09-23 00:06:09 +00:00
|
|
|
// The sprite is positioned in this call, after taking into consideration motion updates and collision
|
2013-10-04 13:41:15 +00:00
|
|
|
if (this.body)
|
|
|
|
{
|
|
|
|
this.body.postUpdate();
|
|
|
|
}
|
2013-09-23 00:06:09 +00:00
|
|
|
|
2013-10-07 23:58:20 +00:00
|
|
|
if (this.fixedToCamera)
|
|
|
|
{
|
|
|
|
this._cache.x = this.game.camera.view.x + this.x;
|
|
|
|
this._cache.y = this.game.camera.view.y + this.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._cache.x = this.x;
|
|
|
|
this._cache.y = this.y;
|
|
|
|
}
|
2013-09-23 02:26:08 +00:00
|
|
|
|
2013-10-04 13:41:15 +00:00
|
|
|
if (this.position.x != this._cache.x || this.position.y != this._cache.y)
|
|
|
|
{
|
|
|
|
this.position.x = this._cache.x;
|
|
|
|
this.position.y = this._cache.y;
|
|
|
|
}
|
2013-09-20 12:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-10 08:03:38 +00:00
|
|
|
Phaser.Sprite.prototype.loadTexture = function (key, frame) {
|
|
|
|
|
|
|
|
this.key = key;
|
|
|
|
|
|
|
|
if (key instanceof Phaser.RenderTexture)
|
|
|
|
{
|
|
|
|
this.currentFrame = this.game.cache.getTextureFrame(key.name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (key == null || this.game.cache.checkImageKey(key) == false)
|
|
|
|
{
|
|
|
|
key = '__default';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.game.cache.isSpriteSheet(key))
|
|
|
|
{
|
|
|
|
this.animations.loadFrameData(this.game.cache.getFrameData(key));
|
|
|
|
|
|
|
|
if (frame !== null)
|
|
|
|
{
|
|
|
|
if (typeof frame === 'string')
|
|
|
|
{
|
|
|
|
this.frameName = frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.frame = frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.currentFrame = this.game.cache.getFrame(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateAnimation();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-23 21:23:17 +00:00
|
|
|
Phaser.Sprite.prototype.deltaAbsX = function () {
|
|
|
|
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
|
|
|
|
}
|
|
|
|
|
|
|
|
Phaser.Sprite.prototype.deltaAbsY = function () {
|
|
|
|
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
|
|
|
|
}
|
|
|
|
|
|
|
|
Phaser.Sprite.prototype.deltaX = function () {
|
|
|
|
return this.x - this.prevX;
|
|
|
|
}
|
|
|
|
|
|
|
|
Phaser.Sprite.prototype.deltaY = function () {
|
|
|
|
return this.y - this.prevY;
|
|
|
|
}
|
|
|
|
|
2013-09-13 03:37:06 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* Moves the sprite so its center is located on the given x and y coordinates.
|
|
|
|
* Doesn't change the origin of the sprite.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.centerOn
|
|
|
|
* @param {number} x - Description.
|
|
|
|
* @param {number} y - Description.
|
|
|
|
*/
|
2013-09-13 03:37:06 +00:00
|
|
|
Phaser.Sprite.prototype.centerOn = function(x, y) {
|
|
|
|
|
|
|
|
this.x = x + (this.x - this.center.x);
|
|
|
|
this.y = y + (this.y - this.center.y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.revive
|
|
|
|
*/
|
2013-10-10 08:03:38 +00:00
|
|
|
Phaser.Sprite.prototype.revive = function(health) {
|
|
|
|
|
|
|
|
if (typeof health === 'undefined') { health = 1; }
|
2013-09-10 00:26:50 +00:00
|
|
|
|
|
|
|
this.alive = true;
|
|
|
|
this.exists = true;
|
|
|
|
this.visible = true;
|
2013-10-10 08:03:38 +00:00
|
|
|
this.health = health;
|
|
|
|
|
2013-09-10 00:26:50 +00:00
|
|
|
this.events.onRevived.dispatch(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.kill
|
|
|
|
*/
|
2013-09-10 00:26:50 +00:00
|
|
|
Phaser.Sprite.prototype.kill = function() {
|
|
|
|
|
|
|
|
this.alive = false;
|
|
|
|
this.exists = false;
|
|
|
|
this.visible = false;
|
2013-10-23 12:30:22 +00:00
|
|
|
|
|
|
|
if (this.events)
|
|
|
|
{
|
|
|
|
this.events.onKilled.dispatch(this);
|
|
|
|
}
|
2013-09-10 00:26:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-13 00:29:57 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.destroy
|
|
|
|
*/
|
|
|
|
Phaser.Sprite.prototype.destroy = function() {
|
|
|
|
|
|
|
|
if (this.group)
|
|
|
|
{
|
|
|
|
this.group.remove(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.input.destroy();
|
|
|
|
this.events.destroy();
|
|
|
|
this.animations.destroy();
|
|
|
|
|
|
|
|
this.alive = false;
|
|
|
|
this.exists = false;
|
|
|
|
this.visible = false;
|
|
|
|
|
|
|
|
this.game = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-10 08:03:38 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.kill
|
|
|
|
*/
|
|
|
|
Phaser.Sprite.prototype.damage = function(amount) {
|
|
|
|
|
|
|
|
if (this.alive)
|
|
|
|
{
|
|
|
|
this.health -= amount;
|
|
|
|
|
|
|
|
if (this.health < 0)
|
|
|
|
{
|
|
|
|
this.kill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.reset
|
|
|
|
*/
|
2013-10-10 08:03:38 +00:00
|
|
|
Phaser.Sprite.prototype.reset = function(x, y, health) {
|
|
|
|
|
|
|
|
if (typeof health === 'undefined') { health = 1; }
|
2013-09-03 16:28:12 +00:00
|
|
|
|
2013-09-09 12:29:33 +00:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
2013-10-04 13:41:15 +00:00
|
|
|
this.position.x = this.x;
|
|
|
|
this.position.y = this.y;
|
2013-09-09 12:29:33 +00:00
|
|
|
this.alive = true;
|
|
|
|
this.exists = true;
|
|
|
|
this.visible = true;
|
2013-10-08 20:09:46 +00:00
|
|
|
this.renderable = true;
|
2013-09-09 12:29:33 +00:00
|
|
|
this._outOfBoundsFired = false;
|
2013-10-10 08:03:38 +00:00
|
|
|
|
|
|
|
this.health = health;
|
|
|
|
|
|
|
|
if (this.body)
|
|
|
|
{
|
|
|
|
this.body.reset();
|
|
|
|
}
|
2013-09-09 16:01:59 +00:00
|
|
|
|
2013-09-03 16:28:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.updateBounds
|
|
|
|
*/
|
2013-09-01 18:52:50 +00:00
|
|
|
Phaser.Sprite.prototype.updateBounds = function() {
|
|
|
|
|
|
|
|
// Update the edge points
|
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
this.offset.setTo(this._cache.a02 - (this.anchor.x * this._cache.width), this._cache.a12 - (this.anchor.y * this._cache.height));
|
2013-09-01 18:52:50 +00:00
|
|
|
|
2013-09-03 14:35:40 +00:00
|
|
|
this.getLocalPosition(this.center, this.offset.x + this._cache.halfWidth, this.offset.y + this._cache.halfHeight);
|
2013-09-02 22:22:24 +00:00
|
|
|
this.getLocalPosition(this.topLeft, this.offset.x, this.offset.y);
|
|
|
|
this.getLocalPosition(this.topRight, this.offset.x + this._cache.width, this.offset.y);
|
|
|
|
this.getLocalPosition(this.bottomLeft, this.offset.x, this.offset.y + this._cache.height);
|
|
|
|
this.getLocalPosition(this.bottomRight, this.offset.x + this._cache.width, this.offset.y + this._cache.height);
|
2013-09-01 18:52:50 +00:00
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
this._cache.left = Phaser.Math.min(this.topLeft.x, this.topRight.x, this.bottomLeft.x, this.bottomRight.x);
|
|
|
|
this._cache.right = Phaser.Math.max(this.topLeft.x, this.topRight.x, this.bottomLeft.x, this.bottomRight.x);
|
|
|
|
this._cache.top = Phaser.Math.min(this.topLeft.y, this.topRight.y, this.bottomLeft.y, this.bottomRight.y);
|
|
|
|
this._cache.bottom = Phaser.Math.max(this.topLeft.y, this.topRight.y, this.bottomLeft.y, this.bottomRight.y);
|
2013-09-01 18:52:50 +00:00
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
this.bounds.setTo(this._cache.left, this._cache.top, this._cache.right - this._cache.left, this._cache.bottom - this._cache.top);
|
2013-09-01 18:52:50 +00:00
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
// This is the coordinate the Sprite was at when the last bounds was created
|
|
|
|
this._cache.boundsX = this._cache.x;
|
|
|
|
this._cache.boundsY = this._cache.y;
|
2013-09-01 18:52:50 +00:00
|
|
|
|
2013-09-09 16:01:59 +00:00
|
|
|
if (this.inWorld == false)
|
|
|
|
{
|
|
|
|
// Sprite WAS out of the screen, is it still?
|
|
|
|
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
|
|
|
|
|
|
|
|
if (this.inWorld)
|
|
|
|
{
|
|
|
|
// It's back again, reset the OOB check
|
|
|
|
this._outOfBoundsFired = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-09-09 12:29:33 +00:00
|
|
|
{
|
2013-09-09 16:01:59 +00:00
|
|
|
// Sprite WAS in the screen, has it now left?
|
|
|
|
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
|
|
|
|
|
|
|
|
if (this.inWorld == false)
|
|
|
|
{
|
|
|
|
this.events.onOutOfBounds.dispatch(this);
|
|
|
|
this._outOfBoundsFired = true;
|
2013-10-08 20:09:46 +00:00
|
|
|
|
|
|
|
if (this.outOfBoundsKill)
|
|
|
|
{
|
|
|
|
this.kill();
|
|
|
|
}
|
2013-09-09 16:01:59 +00:00
|
|
|
}
|
2013-09-09 12:29:33 +00:00
|
|
|
}
|
|
|
|
|
2013-09-01 18:52:50 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.getLocalPosition
|
|
|
|
* @param {Description} p - Description.
|
|
|
|
* @param {number} x - Description.
|
|
|
|
* @param {number} y - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-01 02:15:27 +00:00
|
|
|
Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) {
|
|
|
|
|
2013-09-02 22:22:24 +00:00
|
|
|
p.x = ((this._cache.a11 * this._cache.id * x + -this._cache.a01 * this._cache.id * y + (this._cache.a12 * this._cache.a01 - this._cache.a02 * this._cache.a11) * this._cache.id) * this._cache.scaleX) + this._cache.a02;
|
|
|
|
p.y = ((this._cache.a00 * this._cache.id * y + -this._cache.a10 * this._cache.id * x + (-this._cache.a12 * this._cache.a00 + this._cache.a02 * this._cache.a10) * this._cache.id) * this._cache.scaleY) + this._cache.a12;
|
2013-09-01 02:15:27 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.getLocalUnmodifiedPosition
|
|
|
|
* @param {Description} p - Description.
|
|
|
|
* @param {number} x - Description.
|
|
|
|
* @param {number} y - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-08 21:38:19 +00:00
|
|
|
Phaser.Sprite.prototype.getLocalUnmodifiedPosition = function(p, x, y) {
|
|
|
|
|
|
|
|
p.x = this._cache.a11 * this._cache.idi * x + -this._cache.i01 * this._cache.idi * y + (this._cache.a12 * this._cache.i01 - this._cache.a02 * this._cache.a11) * this._cache.idi;
|
|
|
|
p.y = this._cache.a00 * this._cache.idi * y + -this._cache.i10 * this._cache.idi * x + (-this._cache.a12 * this._cache.a00 + this._cache.a02 * this._cache.i10) * this._cache.idi;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method Phaser.Sprite.prototype.bringToTop
|
|
|
|
*/
|
2013-09-08 21:58:15 +00:00
|
|
|
Phaser.Sprite.prototype.bringToTop = function() {
|
|
|
|
|
|
|
|
if (this.group)
|
|
|
|
{
|
|
|
|
this.group.bringToTop(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.game.world.bringToTop(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-27 12:47:22 +00:00
|
|
|
/**
|
|
|
|
* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
|
|
|
|
* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
|
|
|
|
*
|
|
|
|
* @method play
|
|
|
|
* @param {String} name The name of the animation to be played, e.g. "fire", "walk", "jump".
|
2013-10-01 15:39:39 +00:00
|
|
|
* @param {number} [frameRate=null] The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
|
2013-10-09 12:36:57 +00:00
|
|
|
* @param {boolean} [loop=false] Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
|
|
|
|
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
|
2013-09-27 12:47:22 +00:00
|
|
|
* @return {Phaser.Animation} A reference to playing Animation instance.
|
|
|
|
*/
|
2013-10-09 12:36:57 +00:00
|
|
|
Phaser.Sprite.prototype.play = function (name, frameRate, loop, killOnComplete) {
|
2013-09-27 12:47:22 +00:00
|
|
|
|
|
|
|
if (this.animations)
|
|
|
|
{
|
2013-10-09 12:36:57 +00:00
|
|
|
this.animations.play(name, frameRate, loop, killOnComplete);
|
2013-09-27 12:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-07 23:58:20 +00:00
|
|
|
/**
|
|
|
|
* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
|
|
|
|
* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
|
|
|
|
* If you wish to work in radians instead of degrees use the property Sprite.rotation instead.
|
|
|
|
* @name Phaser.Sprite#angle
|
|
|
|
* @property {number} angle - Gets or sets the Sprites angle of rotation in degrees.
|
|
|
|
*/
|
2013-08-30 19:05:29 +00:00
|
|
|
Object.defineProperty(Phaser.Sprite.prototype, 'angle', {
|
|
|
|
|
|
|
|
get: function() {
|
2013-10-07 23:58:20 +00:00
|
|
|
return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
|
2013-08-30 19:05:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function(value) {
|
2013-10-07 23:58:20 +00:00
|
|
|
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
|
2013-08-30 19:05:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Get the animation frame number.
|
|
|
|
* @returns {Description}
|
|
|
|
*//**
|
|
|
|
* Set the animation frame by frame number.
|
|
|
|
* @param {Description} value - Description
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
Object.defineProperty(Phaser.Sprite.prototype, "frame", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this.animations.frame;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
this.animations.frame = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Get the animation frame name.
|
|
|
|
* @returns {Description}
|
|
|
|
*//**
|
|
|
|
* Set the animation frame by frame name.
|
|
|
|
* @param {Description} value - Description
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
Object.defineProperty(Phaser.Sprite.prototype, "frameName", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this.animations.frameName;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
this.animations.frameName = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Is this sprite visible to the camera or not?
|
2013-10-01 15:39:39 +00:00
|
|
|
* @returns {boolean}
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-02 22:22:24 +00:00
|
|
|
Object.defineProperty(Phaser.Sprite.prototype, "inCamera", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return this._cache.cameraVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Get the input enabled state of this Sprite.
|
|
|
|
* @returns {Description}
|
|
|
|
*//**
|
|
|
|
* Set the ability for this sprite to receive input events.
|
|
|
|
* @param {Description} value - Description
|
|
|
|
*/
|
2013-09-11 02:55:53 +00:00
|
|
|
Object.defineProperty(Phaser.Sprite.prototype, "crop", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this._cropRect;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value instanceof Phaser.Rectangle)
|
|
|
|
{
|
|
|
|
if (this._cropUUID == null)
|
|
|
|
{
|
|
|
|
this._cropUUID = this.game.rnd.uuid();
|
|
|
|
|
|
|
|
PIXI.TextureCache[this._cropUUID] = new PIXI.Texture(PIXI.BaseTextureCache[this.key], {
|
2013-10-04 13:41:15 +00:00
|
|
|
x: Math.floor(value.x),
|
|
|
|
y: Math.floor(value.y),
|
|
|
|
width: Math.floor(value.width),
|
|
|
|
height: Math.floor(value.height)
|
2013-09-11 02:55:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PIXI.TextureCache[this._cropUUID].frame = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._cropRect = value;
|
|
|
|
this.setTexture(PIXI.TextureCache[this._cropUUID]);
|
|
|
|
}
|
2013-10-18 14:12:32 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
this._cropRect = null;
|
2013-09-11 02:55:53 +00:00
|
|
|
|
2013-10-18 14:12:32 +00:00
|
|
|
if (this.animations.isLoaded)
|
|
|
|
{
|
|
|
|
this.animations.refreshFrame();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.setTexture(PIXI.TextureCache[this.key]);
|
|
|
|
}
|
|
|
|
}
|
2013-09-11 02:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Get the input enabled state of this Sprite.
|
|
|
|
* @returns {Description}
|
|
|
|
*//**
|
|
|
|
* Set the ability for this sprite to receive input events.
|
|
|
|
* @param {Description} value - Description
|
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return (this.input.enabled);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
if (this.input.enabled == false)
|
|
|
|
{
|
|
|
|
this.input.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.input.enabled)
|
|
|
|
{
|
|
|
|
this.input.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|