2016-11-28 16:55:13 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2016-12-07 02:28:22 +00:00
|
|
|
var CONST = require('../const');
|
|
|
|
var GameObject = require('../GameObject');
|
|
|
|
var ImageWebGLRenderer = require('./ImageWebGLRenderer');
|
|
|
|
|
2016-11-28 16:55:13 +00:00
|
|
|
/**
|
|
|
|
* An Image is a light-weight object you can use to display anything that doesn't need physics or animation.
|
|
|
|
* It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics.
|
|
|
|
*
|
|
|
|
* @class Phaser.GameObject.Image
|
|
|
|
* @extends Phaser.GameObject
|
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Game} game - A reference to the currently running game.
|
|
|
|
* @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.
|
|
|
|
* @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.
|
|
|
|
* @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.
|
|
|
|
*/
|
2016-12-07 02:28:22 +00:00
|
|
|
var Image = function (state, x, y, key, frame)
|
2016-11-28 16:55:13 +00:00
|
|
|
{
|
|
|
|
var _texture = state.game.textures.get(key);
|
|
|
|
var _frame = _texture.get(frame);
|
|
|
|
|
2016-12-07 02:28:22 +00:00
|
|
|
GameObject.call(this, state, x, y, _texture, _frame);
|
2016-11-28 16:55:13 +00:00
|
|
|
|
2016-12-07 02:28:22 +00:00
|
|
|
this.type = CONST.IMAGE;
|
2016-11-28 16:55:13 +00:00
|
|
|
|
2016-12-07 02:28:22 +00:00
|
|
|
this.render = ImageWebGLRenderer;
|
2016-11-28 16:55:13 +00:00
|
|
|
};
|
|
|
|
|
2016-12-07 02:28:22 +00:00
|
|
|
Image.prototype = Object.create(GameObject.prototype);
|
|
|
|
Image.prototype.constructor = Image;
|
2016-11-28 16:55:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatically called by World.preUpdate.
|
|
|
|
*
|
|
|
|
* @method Phaser.Image#preUpdate
|
|
|
|
* @memberof Phaser.Image
|
2016-12-07 02:28:22 +00:00
|
|
|
*/
|
|
|
|
Image.prototype.preUpdate = function ()
|
2016-11-28 16:55:13 +00:00
|
|
|
{
|
|
|
|
// Would like to get rid of this somehow ...
|
|
|
|
if (this.parent)
|
|
|
|
{
|
|
|
|
this.color.worldAlpha = this.parent.color.worldAlpha;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.defineProperties(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2016-12-07 02:28:22 +00:00
|
|
|
|
|
|
|
module.exports = Image;
|