2017-07-04 00:59:31 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-01-24 12:55:45 +00:00
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
2018-02-06 14:13:30 +00:00
|
|
|
* A Bob Game Object.
|
|
|
|
*
|
|
|
|
* A Bob belongs to a Blitter Game Object. The Blitter is responsible for managing and rendering this object.
|
|
|
|
*
|
|
|
|
* A Bob has a position, alpha value and a frame from a texture that it uses to render with. You can also toggle
|
|
|
|
* the flipped and visible state of the Bob. The Frame the Bob uses to render can be changed dynamically, but it
|
|
|
|
* must be a Frame within the Texture used by the parent Blitter.
|
|
|
|
*
|
|
|
|
* Bob positions are relative to the Blitter parent. So if you move the Blitter parent, all Bob children will
|
|
|
|
* have their positions impacted by this change as well.
|
|
|
|
*
|
|
|
|
* You can manipulate Bob objects directly from your game code, but the creation and destruction of them should be
|
|
|
|
* handled via the Blitter parent.
|
2018-02-01 05:48:56 +00:00
|
|
|
*
|
|
|
|
* @class Bob
|
|
|
|
* @memberOf Phaser.GameObjects.Blitter
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-06 14:13:30 +00:00
|
|
|
* @param {Phaser.GameObjects.Blitter} blitter - The parent Blitter object is responsible for updating this Bob.
|
|
|
|
* @param {number} x - The horizontal position of this Game Object in the world, relative to the parent Blitter position.
|
|
|
|
* @param {number} y - The vertical position of this Game Object in the world, relative to the parent Blitter position.
|
|
|
|
* @param {string|integer} frame - The Frame this Bob will render with, as defined in the Texture the parent Blitter is using.
|
|
|
|
* @param {boolean} visible - Should the Bob render visible or not to start with?
|
2018-02-01 05:48:56 +00:00
|
|
|
*/
|
2017-07-04 00:59:31 +00:00
|
|
|
var Bob = new Class({
|
2017-02-13 23:57:32 +00:00
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
initialize:
|
2017-03-20 23:37:17 +00:00
|
|
|
|
2017-10-02 13:50:02 +00:00
|
|
|
function Bob (blitter, x, y, frame, visible)
|
2017-07-04 00:59:31 +00:00
|
|
|
{
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#parent
|
|
|
|
* @type {Phaser.GameObjects.Blitter}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-02 13:50:02 +00:00
|
|
|
this.parent = blitter;
|
2017-03-20 23:37:17 +00:00
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#x
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 00:59:31 +00:00
|
|
|
this.x = x;
|
2018-02-01 05:48:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#y
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 00:59:31 +00:00
|
|
|
this.y = y;
|
2018-02-01 05:48:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#frame
|
|
|
|
* @type {string|integer}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 00:59:31 +00:00
|
|
|
this.frame = frame;
|
2018-02-01 05:48:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#data
|
|
|
|
* @type {object}
|
|
|
|
* @default {}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 00:59:31 +00:00
|
|
|
this.data = {};
|
2017-02-02 16:55:02 +00:00
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#_visible
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 00:59:31 +00:00
|
|
|
this._visible = visible;
|
2018-02-01 05:48:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#_alpha
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 00:59:31 +00:00
|
|
|
this._alpha = 1;
|
2017-02-13 23:57:32 +00:00
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#flipX
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.flipX = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#flipY
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 00:59:31 +00:00
|
|
|
this.flipY = false;
|
|
|
|
},
|
2017-02-13 23:57:32 +00:00
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter.Bob#setFrame
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} frame - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Blitter.Bob} This Bob Game Object.
|
|
|
|
*/
|
2018-01-20 16:21:42 +00:00
|
|
|
setFrame: function (frame)
|
|
|
|
{
|
|
|
|
if (frame === undefined)
|
|
|
|
{
|
|
|
|
frame = this.parent.frame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame = this.parent.texture.get(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter.Bob#resetFlip
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Blitter.Bob} This Bob Game Object.
|
|
|
|
*/
|
2017-03-20 23:37:17 +00:00
|
|
|
resetFlip: function ()
|
|
|
|
{
|
|
|
|
this.flipX = false;
|
|
|
|
this.flipY = false;
|
2018-02-01 05:48:56 +00:00
|
|
|
|
|
|
|
return this;
|
2017-03-20 23:37:17 +00:00
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter.Bob#reset
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} x - [description]
|
|
|
|
* @param {[type]} y - [description]
|
|
|
|
* @param {[type]} frame - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Blitter.Bob} This Bob Game Object.
|
|
|
|
*/
|
2017-02-02 16:55:02 +00:00
|
|
|
reset: function (x, y, frame)
|
|
|
|
{
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.frame = frame;
|
2018-02-01 05:48:56 +00:00
|
|
|
|
|
|
|
return this;
|
2017-02-13 23:57:32 +00:00
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter.Bob#setFlipX
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} value - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Blitter.Bob} This Bob Game Object.
|
|
|
|
*/
|
2018-01-20 16:21:42 +00:00
|
|
|
setFlipX: function (value)
|
|
|
|
{
|
|
|
|
this.flipX = value;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter.Bob#setFlipY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} value - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Blitter.Bob} This Bob Game Object.
|
|
|
|
*/
|
2018-01-20 16:21:42 +00:00
|
|
|
setFlipY: function (value)
|
|
|
|
{
|
|
|
|
this.flipY = value;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter.Bob#setFlip
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} x - [description]
|
|
|
|
* @param {[type]} y - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Blitter.Bob} This Bob Game Object.
|
|
|
|
*/
|
2018-01-20 16:21:42 +00:00
|
|
|
setFlip: function (x, y)
|
|
|
|
{
|
|
|
|
this.flipX = x;
|
|
|
|
this.flipY = y;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter.Bob#setVisible
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} value - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Blitter.Bob} This Bob Game Object.
|
|
|
|
*/
|
2018-01-20 16:21:42 +00:00
|
|
|
setVisible: function (value)
|
|
|
|
{
|
|
|
|
this.visible = value;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter.Bob#setAlpha
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} value - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Blitter.Bob} This Bob Game Object.
|
|
|
|
*/
|
2018-01-20 16:21:42 +00:00
|
|
|
setAlpha: function (value)
|
|
|
|
{
|
|
|
|
this.alpha = value;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Blitter.Bob#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-13 23:57:32 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
2017-08-14 12:13:11 +00:00
|
|
|
this.parent.dirty = true;
|
|
|
|
|
|
|
|
this.parent.children.remove(this);
|
|
|
|
|
2017-02-13 23:57:32 +00:00
|
|
|
this.parent = undefined;
|
|
|
|
this.frame = undefined;
|
|
|
|
this.data = undefined;
|
2017-07-04 00:59:31 +00:00
|
|
|
},
|
2017-02-13 23:57:32 +00:00
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#visible
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-13 23:57:32 +00:00
|
|
|
visible: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._visible;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this._visible = value;
|
|
|
|
this.parent.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-01 05:48:56 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Blitter.Bob#alpha
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-13 23:57:32 +00:00
|
|
|
alpha: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._alpha;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this._alpha = value;
|
|
|
|
this.parent.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-01-24 12:55:45 +00:00
|
|
|
module.exports = Bob;
|