/** * @author Richard Davey * @copyright 2016 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ /** * Sprites are the lifeblood of your game, used for nearly everything visual. * * At its most basic a Sprite consists of a set of coordinates and a texture that is rendered to the canvas. * They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input), * events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases. * * @class Phaser.GameObject.Sprite * @constructor * @extends Phaser.GameObject * @param {Phaser.Game} game - A reference to the currently running game. * @param {number} x - The x coordinate (in world space) to position the Sprite at. * @param {number} y - The y coordinate (in world space) to position the Sprite at. * @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. * @param {string|number} frame - If this Sprite 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. */ Phaser.GameObject.Sprite = function (game, x, y, key, frame) { this.game = game; var _texture = game.textures.get(key); var _frame = _texture.get(frame); Phaser.GameObject.call(this, game, x, y, _texture, _frame); /** * @property {number} type - The const type of this object. * @readonly */ this.type = Phaser.SPRITE; /** * @property {number} physicsType - The const physics body type of this object. * @readonly */ this.physicsType = Phaser.SPRITE; this.children = new Phaser.Component.Children(this); }; Phaser.GameObject.Sprite.prototype = Object.create(Phaser.GameObject.prototype); Phaser.GameObject.Sprite.prototype.constructor = Phaser.GameObject.Sprite; /** * Automatically called by World.preUpdate. * * @method Phaser.Sprite#preUpdate * @memberof Phaser.Sprite */ Phaser.GameObject.Sprite.prototype.preUpdate = function () { if (this.parent) { this.color.worldAlpha = this.parent.color.worldAlpha; } this.children.preUpdate(); }; // Phaser.GameObject.Sprite.prototype.update = function () // { // }; // Phaser.GameObject.Sprite.prototype.postUpdate = function () // { // }; Object.defineProperties(Phaser.GameObject.Sprite.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; } } });