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
+12 -1
View File
@@ -154,10 +154,21 @@ Phaser.Camera.prototype = {
break;
}
},
/**
* Move the camera focus on a display object instantly.
* @method Phaser.Camera#focusOn
* @param {any} displayObject - The display object to focus the camera on. Must have visible x/y properties.
*/
focusOn: function (displayObject) {
this.setPosition(Math.round(displayObject.x - this.view.halfWidth), Math.round(displayObject.y - this.view.halfHeight));
},
/**
* Move the camera focus to a location instantly.
* Move the camera focus on a location instantly.
* @method Phaser.Camera#focusOnXY
* @param {number} x - X position.
* @param {number} y - Y position.
+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}
+2 -2
View File
@@ -883,7 +883,7 @@ Phaser.Physics.Arcade.prototype = {
{
if (separate)
{
console.log('x over', this._overlap);
// console.log('x over', this._overlap);
object.x = object.x - this._overlap;
if (object.bounce.x == 0)
@@ -960,7 +960,7 @@ Phaser.Physics.Arcade.prototype = {
if (this._overlap != 0)
{
console.log('y over', this._overlap);
// console.log('y over', this._overlap);
if (separate)
{
+12 -6
View File
@@ -105,8 +105,10 @@ Phaser.Physics.Arcade.Body.prototype = {
this.embedded = false;
this.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
// this.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
// this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preRotation = this.sprite.angle;
this.x = this.preX;
@@ -221,12 +223,16 @@ Phaser.Physics.Arcade.Body.prototype = {
this.angularVelocity = 0;
this.angularAcceleration = 0;
this.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
// this.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
// this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preRotation = this.sprite.angle;
this.x = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.y = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
// this.x = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
// this.y = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.x = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.y = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.rotation = this.sprite.angle;
},
+45
View File
@@ -460,6 +460,7 @@ Phaser.Utils.Debug.prototype = {
this.line('angle: ' + sprite.angle.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1));
this.line('visible: ' + sprite.visible + ' in camera: ' + sprite.inCamera);
this.line('body x: ' + sprite.body.x.toFixed(1) + ' y: ' + sprite.body.y.toFixed(1));
this.stop();
// 0 = scaleX
// 1 = skewY
@@ -510,6 +511,7 @@ Phaser.Utils.Debug.prototype = {
this.line('scaleY: ' + sprite.worldTransform[4]);
this.line('transX: ' + sprite.worldTransform[2]);
this.line('transY: ' + sprite.worldTransform[5]);
this.stop();
},
@@ -539,6 +541,49 @@ Phaser.Utils.Debug.prototype = {
this.line('scaleY: ' + sprite.localTransform[4]);
this.line('transX: ' + sprite.localTransform[2]);
this.line('transY: ' + sprite.localTransform[5]);
this.stop();
},
renderSpriteCoords: function (sprite, x, y, color) {
if (this.context == null)
{
return;
}
color = color || 'rgb(255, 255, 255)';
this.start(x, y, color);
this.line(sprite.name);
this.line('x: ' + sprite.x);
this.line('y: ' + sprite.y);
this.line('local x: ' + sprite.localTransform[2]);
this.line('local y: ' + sprite.localTransform[5]);
this.line('world x: ' + sprite.worldTransform[2]);
this.line('world y: ' + sprite.worldTransform[5]);
this.stop();
},
renderGroupInfo: function (group, x, y, color) {
if (this.context == null)
{
return;
}
color = color || 'rgb(255, 255, 255)';
this.start(x, y, color);
this.line('Group (size: ' + group.length + ')');
this.line('x: ' + group.x);
this.line('y: ' + group.y);
this.stop();
},