mirror of
https://github.com/photonstorm/phaser
synced 2024-12-04 02:20:23 +00:00
281 lines
5.3 KiB
JavaScript
281 lines
5.3 KiB
JavaScript
/**
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
*/
|
|
|
|
Phaser.GameObject.Blitter.Bob = function (parent, x, y, key, frame, visible)
|
|
{
|
|
if (visible === undefined) { visible = true; }
|
|
|
|
this.parent = parent;
|
|
|
|
this.texture = parent.state.game.textures.get(key);
|
|
|
|
this.frame = this.texture.get(frame);
|
|
|
|
this.transform = new Phaser.Component.Transform(this, x, y);
|
|
|
|
// Don't need to spam the UpdateManager with a Transform with no children
|
|
this.transform.immediate = true;
|
|
|
|
this.type = 0;
|
|
|
|
// Do we need this?
|
|
// this.color = new Phaser.Component.Color(this);
|
|
|
|
this.alpha = 1;
|
|
|
|
this.scaleMode = Phaser.scaleModes.DEFAULT;
|
|
|
|
this.visible = visible;
|
|
};
|
|
|
|
Phaser.GameObject.Blitter.Bob.prototype.constructor = Phaser.GameObject.Blitter.Bob;
|
|
|
|
Phaser.GameObject.Blitter.Bob.prototype = {
|
|
|
|
destroy: function ()
|
|
{
|
|
this.parent.children.remove(this);
|
|
|
|
this.transform.destroy();
|
|
|
|
this.texture = undefined;
|
|
this.frame = undefined;
|
|
|
|
this.parent = undefined;
|
|
}
|
|
|
|
};
|
|
|
|
Object.defineProperties(Phaser.GameObject.Blitter.Bob.prototype, {
|
|
|
|
// Transform getters / setters
|
|
|
|
x: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._posX;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform._posX = value;
|
|
this.transform.dirty = true;
|
|
}
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._posY;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform._posY = value;
|
|
this.transform.dirty = true;
|
|
}
|
|
|
|
},
|
|
|
|
scale: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._scaleX;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform._scaleX = value;
|
|
this.transform._scaleY = value;
|
|
this.transform.dirty = true;
|
|
this.transform.updateCache();
|
|
}
|
|
|
|
},
|
|
|
|
scaleX: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._scaleX;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform._scaleX = value;
|
|
this.transform.dirty = true;
|
|
this.transform.updateCache();
|
|
}
|
|
|
|
},
|
|
|
|
scaleY: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._scaleY;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform._scaleY = value;
|
|
this.transform.dirty = true;
|
|
this.transform.updateCache();
|
|
}
|
|
|
|
},
|
|
|
|
anchor: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._anchorX;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform.setAnchor(value);
|
|
}
|
|
|
|
},
|
|
|
|
anchorX: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._anchorX;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform._anchorX = value;
|
|
this.transform.dirty = true;
|
|
}
|
|
|
|
},
|
|
|
|
anchorY: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._anchorY;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform._anchorY = value;
|
|
this.transform.dirty = true;
|
|
}
|
|
|
|
},
|
|
|
|
pivotX: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._pivotX;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform._pivotX = value;
|
|
this.transform.dirty = true;
|
|
this.transform.updateCache();
|
|
}
|
|
|
|
},
|
|
|
|
pivotY: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._pivotY;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.transform._pivotY = value;
|
|
this.transform.dirty = true;
|
|
this.transform.updateCache();
|
|
}
|
|
|
|
},
|
|
|
|
angle: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return Phaser.Math.wrapAngle(this.rotation * Phaser.Math.RAD_TO_DEG);
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
this.rotation = Phaser.Math.wrapAngle(value) * Phaser.Math.DEG_TO_RAD;
|
|
}
|
|
|
|
},
|
|
|
|
rotation: {
|
|
|
|
enumerable: true,
|
|
|
|
get: function ()
|
|
{
|
|
return this.transform._rotation;
|
|
},
|
|
|
|
set: function (value)
|
|
{
|
|
if (this.transform._rotation === value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.transform._rotation = value;
|
|
this.transform.dirty = true;
|
|
|
|
if (this.transform._rotation % Phaser.Math.PI2)
|
|
{
|
|
this.transform.cache.sr = Math.sin(this.transform._rotation);
|
|
this.transform.cache.cr = Math.cos(this.transform._rotation);
|
|
this.transform.updateCache();
|
|
this.transform.hasLocalRotation = true;
|
|
}
|
|
else
|
|
{
|
|
this.transform.hasLocalRotation = false;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
});
|