2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2016-04-04 21:15:01 +00:00
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-09-16 16:35:08 +00:00
|
|
|
* Sprites are the lifeblood of your game, used for nearly everything visual.
|
2013-11-28 15:57:09 +00:00
|
|
|
*
|
2013-10-25 14:02:21 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2016-10-08 02:05:42 +00:00
|
|
|
* @class Phaser.GameObjects.Sprite
|
2013-10-01 12:54:29 +00:00
|
|
|
* @constructor
|
2014-02-21 13:25:08 +00:00
|
|
|
* @extends PIXI.Sprite
|
2015-03-01 07:00:17 +00:00
|
|
|
* @extends Phaser.Component.Core
|
|
|
|
* @extends Phaser.Component.Angle
|
|
|
|
* @extends Phaser.Component.Animation
|
|
|
|
* @extends Phaser.Component.AutoCull
|
|
|
|
* @extends Phaser.Component.Bounds
|
|
|
|
* @extends Phaser.Component.BringToTop
|
|
|
|
* @extends Phaser.Component.Crop
|
|
|
|
* @extends Phaser.Component.Delta
|
|
|
|
* @extends Phaser.Component.Destroy
|
|
|
|
* @extends Phaser.Component.FixedToCamera
|
2015-03-30 12:51:47 +00:00
|
|
|
* @extends Phaser.Component.Health
|
|
|
|
* @extends Phaser.Component.InCamera
|
2015-03-01 07:00:17 +00:00
|
|
|
* @extends Phaser.Component.InputEnabled
|
|
|
|
* @extends Phaser.Component.InWorld
|
|
|
|
* @extends Phaser.Component.LifeSpan
|
|
|
|
* @extends Phaser.Component.LoadTexture
|
|
|
|
* @extends Phaser.Component.Overlap
|
|
|
|
* @extends Phaser.Component.PhysicsBody
|
|
|
|
* @extends Phaser.Component.Reset
|
|
|
|
* @extends Phaser.Component.ScaleMinMax
|
|
|
|
* @extends Phaser.Component.Smoothed
|
2013-10-25 14:02:21 +00:00
|
|
|
* @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.
|
2013-11-13 20:57:09 +00:00
|
|
|
* @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.
|
2013-10-25 14:02:21 +00:00
|
|
|
* @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.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2016-10-08 02:05:42 +00:00
|
|
|
Phaser.GameObjects.Sprite = function (game, x, y, key, frame) {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-08-31 20:50:34 +00:00
|
|
|
x = x || 0;
|
|
|
|
y = y || 0;
|
2013-09-11 02:55:53 +00:00
|
|
|
key = key || null;
|
2013-08-31 20:50:34 +00:00
|
|
|
frame = frame || null;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* @property {number} type - The const type of this object.
|
|
|
|
* @readonly
|
|
|
|
*/
|
2014-02-07 19:44:14 +00:00
|
|
|
this.type = Phaser.SPRITE;
|
2013-09-10 00:26:50 +00:00
|
|
|
|
2015-03-23 15:04:27 +00:00
|
|
|
/**
|
|
|
|
* @property {number} physicsType - The const physics body type of this object.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.physicsType = Phaser.SPRITE;
|
|
|
|
|
* PIXI.Texture.fromImage, PIXI.BaseTexture.fromImage and PIXI.Sprite.fromImage have all been removed. They should never have actually been used, as they bypass the Phaser Loader, and don't factor in CORs or any other advanced loader settings.
* The PIXI.BaseTexture.imageUrl property has been removed, as it was never actually populated.
* The PIXI.BaseTexture._UID property has been removed, as it was never actually used internally.
* All references to PIXI.BaseTextureCache have been removed (primarily from BaseTexture.destroy and Texture.destroy), as the BaseTextureCache was never used internally by Phaser, or by our custom version of Pixi.
* PIXI.TextureCache has been removed. It was only ever used by the __default and __missing images that Phaser generates on start-up. It wasn't used internally by Phaser anywhere else, and the only references Pixi has to it have all been removed. If you need it in your own game, please refactor it to avoid it, or re-create the object on the PIXI global object.
* Canvases created by `BaseTexture.fromCanvas` no longer have the `_pixiId` property attached to them, as this was never used internally by Phaser or Pixi.
* PIXI.BaseTexture.updateSourceImage is now deprecated. Please use `Sprite.loadTexture` instead.
* The property PIXI.BaseTextureCacheIdGenerator has been removed, as it is no longer used internally by Phaser or Pixi.
* PIXI.Texture.addTextureToCache has been removed. The PIXI Texture Cache was never actually used by Phaser, and was leading to complications internally.
* PIXI.Texture.removeTextureFromCache has been removed. The PIXI Texture Cache was never actually used by Phaser, and was leading to complications internally.
* PIXI.Texture.fromFrame and PIXI.Sprite.fromFrame have been removed. They relied on the PIXI Texture Cache, which was never actually used by Phaser, and was never used internally by Pixi either.
* The property PIXI.TextureCacheIdGenerator has been removed, as it was not used internally.
* The property PIXI.FrameCache has been removed, as it was not used internally.
2016-07-06 20:47:27 +00:00
|
|
|
PIXI.Sprite.call(this, Phaser.Cache.DEFAULT);
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2015-02-17 06:00:41 +00:00
|
|
|
Phaser.Component.Core.init.call(this, game, x, y, key, frame);
|
2014-06-05 01:33:13 +00:00
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
};
|
|
|
|
|
2016-10-08 02:05:42 +00:00
|
|
|
Phaser.GameObjects.Sprite.prototype = Object.create(PIXI.Sprite.prototype);
|
|
|
|
Phaser.GameObjects.Sprite.prototype.constructor = Phaser.GameObjects.Sprite;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2016-10-08 02:05:42 +00:00
|
|
|
Phaser.Component.Core.install.call(Phaser.GameObjects.Sprite.prototype, [
|
2015-02-23 04:44:11 +00:00
|
|
|
'Angle',
|
|
|
|
'Animation',
|
|
|
|
'AutoCull',
|
|
|
|
'Bounds',
|
|
|
|
'BringToTop',
|
|
|
|
'Crop',
|
|
|
|
'Delta',
|
|
|
|
'Destroy',
|
|
|
|
'FixedToCamera',
|
2015-03-30 12:51:47 +00:00
|
|
|
'Health',
|
|
|
|
'InCamera',
|
2015-02-23 04:44:11 +00:00
|
|
|
'InputEnabled',
|
|
|
|
'InWorld',
|
|
|
|
'LifeSpan',
|
|
|
|
'LoadTexture',
|
|
|
|
'Overlap',
|
|
|
|
'PhysicsBody',
|
|
|
|
'Reset',
|
|
|
|
'ScaleMinMax',
|
|
|
|
'Smoothed'
|
2015-03-23 15:04:27 +00:00
|
|
|
]);
|
2015-02-23 04:44:11 +00:00
|
|
|
|
2016-10-08 02:05:42 +00:00
|
|
|
Phaser.GameObjects.Sprite.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate;
|
|
|
|
Phaser.GameObjects.Sprite.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate;
|
|
|
|
Phaser.GameObjects.Sprite.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;
|
|
|
|
Phaser.GameObjects.Sprite.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
|
2015-02-23 04:44:11 +00:00
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
/**
|
2014-02-07 18:44:58 +00:00
|
|
|
* Automatically called by World.preUpdate.
|
2013-10-25 14:02:21 +00:00
|
|
|
*
|
2015-03-01 07:00:17 +00:00
|
|
|
* @method
|
2016-10-08 02:05:42 +00:00
|
|
|
* @memberof Phaser.GameObjects.Sprite
|
2014-02-09 03:48:31 +00:00
|
|
|
* @return {boolean} True if the Sprite was rendered, otherwise false.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2016-10-08 02:05:42 +00:00
|
|
|
Phaser.GameObjects.Sprite.prototype.preUpdate = function () {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2015-02-25 00:59:27 +00:00
|
|
|
if (!this.preUpdatePhysics() || !this.preUpdateLifeSpan() || !this.preUpdateInWorld())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-24 03:27:28 +00:00
|
|
|
|
2015-02-25 00:59:27 +00:00
|
|
|
return this.preUpdateCore();
|
2013-10-24 03:27:28 +00:00
|
|
|
|
2013-11-01 02:07:21 +00:00
|
|
|
};
|