2014-02-06 19:34:05 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2014-02-06 19:34:05 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-09-16 16:35:08 +00:00
|
|
|
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
|
2014-02-07 17:14:10 +00:00
|
|
|
* It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
|
2014-02-06 19:34:05 +00:00
|
|
|
*
|
2016-10-09 21:27:58 +00:00
|
|
|
* @class Phaser.GameObject.Image
|
2016-10-12 23:08:26 +00:00
|
|
|
* @extends Phaser.Components.BaseTransform
|
2014-02-06 19:34:05 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Game} game - A reference to the currently running game.
|
2015-05-08 03:12:07 +00:00
|
|
|
* @param {number} [x=0] - The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
|
|
|
* @param {number} [y=0] - The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in.
|
2016-10-12 23:08:26 +00:00
|
|
|
* @param {string} [key] - The texture used by the Image during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
|
2015-05-08 03:12:07 +00:00
|
|
|
* @param {string|number} [frame] - If this Image is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
|
2014-02-06 19:34:05 +00:00
|
|
|
*/
|
2016-10-11 13:52:17 +00:00
|
|
|
Phaser.GameObject.Image = function (game, x, y, key, frame)
|
|
|
|
{
|
2016-10-12 23:08:26 +00:00
|
|
|
this.game = game;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2016-10-14 03:09:22 +00:00
|
|
|
Phaser.Component.BaseTransform.call(this, x, y);
|
|
|
|
|
2014-02-06 19:34:05 +00:00
|
|
|
/**
|
|
|
|
* @property {number} type - The const type of this object.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.type = Phaser.IMAGE;
|
|
|
|
|
2016-10-14 03:09:22 +00:00
|
|
|
this.name = '';
|
|
|
|
|
2016-10-13 00:54:18 +00:00
|
|
|
this.parent = null;
|
|
|
|
|
2016-10-12 23:08:26 +00:00
|
|
|
this.texture = game.textures.get(key);
|
2014-02-06 19:34:05 +00:00
|
|
|
|
2016-10-12 23:08:26 +00:00
|
|
|
this.frame = this.texture.get(frame);
|
2016-10-12 14:19:04 +00:00
|
|
|
|
2016-10-13 00:54:18 +00:00
|
|
|
// Allows you to turn off a GO from rendering, but still render its children
|
|
|
|
this.skipRender = (key === undefined);
|
|
|
|
|
|
|
|
this.visible = true;
|
|
|
|
|
2016-10-12 14:19:04 +00:00
|
|
|
this.data = new Phaser.Component.Data(this);
|
2016-10-13 00:54:18 +00:00
|
|
|
|
|
|
|
// Temporary for now?
|
|
|
|
this.alpha = 1;
|
|
|
|
this.blendMode = Phaser.blendModes.NORMAL;
|
|
|
|
this.scaleMode = Phaser.scaleModes.DEFAULT;
|
|
|
|
this.exists = true;
|
2014-02-06 19:34:05 +00:00
|
|
|
};
|
|
|
|
|
2016-10-13 00:54:18 +00:00
|
|
|
Phaser.GameObject.Image.prototype = Object.create(Phaser.Component.BaseTransform.prototype);
|
2016-10-09 21:27:58 +00:00
|
|
|
Phaser.GameObject.Image.prototype.constructor = Phaser.GameObject.Image;
|
2014-02-06 19:34:05 +00:00
|
|
|
|
|
|
|
/**
|
2014-02-07 02:31:29 +00:00
|
|
|
* Automatically called by World.preUpdate.
|
2014-02-06 19:34:05 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Image#preUpdate
|
|
|
|
* @memberof Phaser.Image
|
|
|
|
*/
|
2016-10-11 13:52:17 +00:00
|
|
|
Phaser.GameObject.Image.prototype.preUpdate = function ()
|
|
|
|
{
|
2016-10-14 03:09:22 +00:00
|
|
|
// this.transform.update();
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2016-10-13 00:54:18 +00:00
|
|
|
|
|
|
|
Phaser.GameObject.Image.prototype.update = function ()
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.GameObject.Image.prototype.postUpdate = function ()
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.defineProperties(Phaser.GameObject.Image.prototype, {
|
|
|
|
|
|
|
|
width: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._scaleX * this.frame.realWidth;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.scaleX = value / this.frame.realWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
height: {
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.transform._scaleY * this.frame.realHeight;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.scaleY = value / this.frame.realHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|