Sprite.loadTexture added.

This commit is contained in:
photonstorm
2013-10-10 09:03:38 +01:00
parent f10f9324ad
commit a7230aa769
16 changed files with 2079 additions and 2307 deletions
+97 -4
View File
@@ -263,6 +263,11 @@ Phaser.Sprite = function (game, x, y, key, frame) {
*/
this.body = new Phaser.Physics.Arcade.Body(this);
/**
* @property {number} health - Health value. Used in combination with damage() to allow for quick killing of Sprites.
*/
this.health = 1;
/**
* @property {Description} velocity - Description.
*/
@@ -349,6 +354,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
this.prevY = this.y;
this.updateCache();
this.updateAnimation();
// Re-run the camera visibility check
if (this._cache.dirty)
@@ -407,7 +413,10 @@ Phaser.Sprite.prototype.updateCache = function() {
this._cache.dirty = true;
}
// Frame updated?
}
Phaser.Sprite.prototype.updateAnimation = function() {
if (this.currentFrame && this.currentFrame.uuid != this._cache.frameID)
{
this._cache.frameWidth = this.texture.frame.width;
@@ -461,6 +470,47 @@ Phaser.Sprite.prototype.postUpdate = function() {
}
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();
}
Phaser.Sprite.prototype.deltaAbsX = function () {
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
}
@@ -497,11 +547,15 @@ Phaser.Sprite.prototype.centerOn = function(x, y) {
*
* @method Phaser.Sprite.prototype.revive
*/
Phaser.Sprite.prototype.revive = function() {
Phaser.Sprite.prototype.revive = function(health) {
if (typeof health === 'undefined') { health = 1; }
this.alive = true;
this.exists = true;
this.visible = true;
this.health = health;
this.events.onRevived.dispatch(this);
}
@@ -520,12 +574,33 @@ Phaser.Sprite.prototype.kill = function() {
}
/**
* Description.
*
* @method Phaser.Sprite.prototype.kill
*/
Phaser.Sprite.prototype.damage = function(amount) {
if (this.alive)
{
this.health -= amount;
if (this.health < 0)
{
this.kill();
}
}
}
/**
* Description.
*
* @method Phaser.Sprite.prototype.reset
*/
Phaser.Sprite.prototype.reset = function(x, y) {
Phaser.Sprite.prototype.reset = function(x, y, health) {
if (typeof health === 'undefined') { health = 1; }
this.x = x;
this.y = y;
@@ -536,7 +611,13 @@ Phaser.Sprite.prototype.reset = function(x, y) {
this.visible = true;
this.renderable = true;
this._outOfBoundsFired = false;
this.body.reset();
this.health = health;
if (this.body)
{
this.body.reset();
}
}
@@ -741,6 +822,18 @@ Object.defineProperty(Phaser.Sprite.prototype, "inCamera", {
});
/**
*
* @returns {boolean}
*/
Object.defineProperty(Phaser.Sprite.prototype, "worldX", {
get: function () {
return 1;
}
});
/**
* Get the input enabled state of this Sprite.
* @returns {Description}