mirror of
https://github.com/wassname/phaser.git
synced 2026-07-23 13:00:41 +08:00
Updated documentation.
This commit is contained in:
+154
-63
@@ -54,6 +54,10 @@
|
||||
<a href="Phaser.AnimationParser.html">AnimationParser</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapData.html">BitmapData</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.BitmapText.html">BitmapText</a>
|
||||
</li>
|
||||
@@ -138,6 +142,10 @@
|
||||
<a href="Phaser.Events.html">Events</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Filter.html">Filter</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Frame.html">Frame</a>
|
||||
</li>
|
||||
@@ -302,6 +310,26 @@
|
||||
<a href="Phaser.Text.html">Text</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Tile.html">Tile</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Tilemap.html">Tilemap</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.TilemapParser.html">TilemapParser</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Tileset.html">Tileset</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.TileSprite.html">TileSprite</a>
|
||||
</li>
|
||||
@@ -310,6 +338,10 @@
|
||||
<a href="Phaser.Time.html">Time</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Timer.html">Timer</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="Phaser.Touch.html">Touch</a>
|
||||
</li>
|
||||
@@ -356,6 +388,14 @@
|
||||
<a href="global.html#HEXtoRGB">HEXtoRGB</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#render">render</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#renderXY">renderXY</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="global.html#right">right</a>
|
||||
</li>
|
||||
@@ -388,17 +428,19 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a new `Sprite` object. Sprites are the lifeblood of your game, used for nearly everything visual.
|
||||
* @class Phaser.Sprite
|
||||
*
|
||||
* @classdesc Create a new `Sprite` object. 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.Sprite
|
||||
* @constructor
|
||||
* @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|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|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.Sprite = function (game, x, y, key, frame) {
|
||||
@@ -409,55 +451,55 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
frame = frame || null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
|
||||
* @default
|
||||
*/
|
||||
/**
|
||||
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
|
||||
* @default
|
||||
*/
|
||||
this.exists = true;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @property {boolean} alive - This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering.
|
||||
* @default
|
||||
*/
|
||||
* @default
|
||||
*/
|
||||
this.alive = true;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
|
||||
*/
|
||||
*/
|
||||
this.group = null;
|
||||
|
||||
/**
|
||||
* @property {string} name - The user defined name given to this Sprite.
|
||||
* @default
|
||||
*/
|
||||
* @property {string} name - The user defined name given to this Sprite.
|
||||
* @default
|
||||
*/
|
||||
this.name = '';
|
||||
|
||||
/**
|
||||
* @property {number} type - The const type of this object.
|
||||
* @default
|
||||
*/
|
||||
* @property {number} type - The const type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.type = Phaser.SPRITE;
|
||||
|
||||
/**
|
||||
* @property {number} renderOrderID - Used by the Renderer and Input Manager to control picking order.
|
||||
* @default
|
||||
*/
|
||||
* @property {number} renderOrderID - Used by the Renderer and Input Manager to control picking order.
|
||||
* @default
|
||||
*/
|
||||
this.renderOrderID = -1;
|
||||
|
||||
/**
|
||||
* If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
|
||||
* The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
|
||||
* @property {number} lifespan - The lifespan of the Sprite (in ms) before it will be killed.
|
||||
* @default
|
||||
*/
|
||||
* The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
|
||||
* @property {number} lifespan - The lifespan of the Sprite (in ms) before it will be killed.
|
||||
* @default
|
||||
*/
|
||||
this.lifespan = 0;
|
||||
|
||||
/**
|
||||
* @property {Events} events - The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
|
||||
* @property {Phaser.Events} events - The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
|
||||
*/
|
||||
this.events = new Phaser.Events(this);
|
||||
|
||||
@@ -467,12 +509,12 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
this.animations = new Phaser.AnimationManager(this);
|
||||
|
||||
/**
|
||||
* @property {InputHandler} input - The Input Handler Component.
|
||||
* @property {Phaser.InputHandler} input - The Input Handler Component.
|
||||
*/
|
||||
this.input = new Phaser.InputHandler(this);
|
||||
|
||||
/**
|
||||
* @property {string|Phaser.RenderTexture|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.
|
||||
* @property {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, BitmapData or PIXI.Texture.
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
@@ -487,6 +529,12 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
|
||||
this.currentFrame = this.game.cache.getTextureFrame(key.name);
|
||||
}
|
||||
else if (key instanceof Phaser.BitmapData)
|
||||
{
|
||||
PIXI.Sprite.call(this, key.texture, key.textureFrame);
|
||||
|
||||
this.currentFrame = key.textureFrame;
|
||||
}
|
||||
else if (key instanceof PIXI.Texture)
|
||||
{
|
||||
PIXI.Sprite.call(this, key);
|
||||
@@ -495,11 +543,16 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (key == null || this.game.cache.checkImageKey(key) == false)
|
||||
if (key === null || typeof key === 'undefined')
|
||||
{
|
||||
key = '__default';
|
||||
this.key = key;
|
||||
}
|
||||
else if (typeof key === 'string' && this.game.cache.checkImageKey(key) === false)
|
||||
{
|
||||
key = '__missing';
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
|
||||
|
||||
@@ -537,22 +590,22 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
* Setting than anchor to 0.5,0.5 means the textures origin is centered
|
||||
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
|
||||
*
|
||||
* @property {Phaser.Point} anchor - The anchor around with Sprite rotation and scaling takes place.
|
||||
* @property {Phaser.Point} anchor - The anchor around which rotation and scaling takes place.
|
||||
*/
|
||||
this.anchor = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {number} x - The x coordinate (in world space) of this Sprite.
|
||||
* @property {number} x - The x coordinate in world space of this Sprite.
|
||||
*/
|
||||
this.x = x;
|
||||
|
||||
/**
|
||||
* @property {number} y - The y coordinate (in world space) of this Sprite.
|
||||
* @property {number} y - The y coordinate in world space of this Sprite.
|
||||
*/
|
||||
this.y = y;
|
||||
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} world - The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
|
||||
@@ -570,60 +623,82 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} scale - The scale of the Sprite when rendered. By default it's set to 1 (no scale). You can modify it via scale.x or scale.y or scale.setTo(x, y). A value of 1 means no change to the scale, 0.5 means "half the size", 2 means "twice the size", etc.
|
||||
*/
|
||||
*/
|
||||
this.scale = new Phaser.Point(1, 1);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} _cache - A mini cache for storing all of the calculated values.
|
||||
* @property {object} _cache - A mini cache for storing all of the calculated values.
|
||||
* @private
|
||||
*/
|
||||
this._cache = {
|
||||
this._cache = {
|
||||
|
||||
dirty: false,
|
||||
|
||||
// Transform cache
|
||||
a00: -1, a01: -1, a02: -1, a10: -1, a11: -1, a12: -1, id: -1,
|
||||
a00: -1,
|
||||
a01: -1,
|
||||
a02: -1,
|
||||
a10: -1,
|
||||
a11: -1,
|
||||
a12: -1,
|
||||
id: -1,
|
||||
|
||||
// Input specific transform cache
|
||||
i01: -1, i10: -1, idi: -1,
|
||||
i01: -1,
|
||||
i10: -1,
|
||||
idi: -1,
|
||||
|
||||
// Bounds check
|
||||
left: null, right: null, top: null, bottom: null,
|
||||
left: null,
|
||||
right: null,
|
||||
top: null,
|
||||
bottom: null,
|
||||
|
||||
// delta cache
|
||||
prevX: x, prevY: y,
|
||||
prevX: x,
|
||||
prevY: y,
|
||||
|
||||
// The previous calculated position
|
||||
x: -1, y: -1,
|
||||
x: -1,
|
||||
y: -1,
|
||||
|
||||
// The actual scale values based on the worldTransform
|
||||
scaleX: 1, scaleY: 1,
|
||||
scaleX: 1,
|
||||
scaleY: 1,
|
||||
|
||||
// The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size
|
||||
width: this.currentFrame.sourceSizeW, height: this.currentFrame.sourceSizeH,
|
||||
width: this.currentFrame.sourceSizeW,
|
||||
height: this.currentFrame.sourceSizeH,
|
||||
|
||||
// The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size
|
||||
halfWidth: Math.floor(this.currentFrame.sourceSizeW / 2), halfHeight: Math.floor(this.currentFrame.sourceSizeH / 2),
|
||||
halfWidth: Math.floor(this.currentFrame.sourceSizeW / 2),
|
||||
halfHeight: Math.floor(this.currentFrame.sourceSizeH / 2),
|
||||
|
||||
// The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size
|
||||
calcWidth: -1, calcHeight: -1,
|
||||
calcWidth: -1,
|
||||
calcHeight: -1,
|
||||
|
||||
// The current frame details
|
||||
// frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
|
||||
frameID: -1, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
|
||||
frameID: -1,
|
||||
frameWidth: this.currentFrame.width,
|
||||
frameHeight: this.currentFrame.height,
|
||||
|
||||
// If this sprite visible to the camera (regardless of being set to visible or not)
|
||||
cameraVisible: true,
|
||||
|
||||
// Crop cache
|
||||
cropX: 0, cropY: 0, cropWidth: this.currentFrame.sourceSizeW, cropHeight: this.currentFrame.sourceSizeH
|
||||
cropX: 0,
|
||||
cropY: 0,
|
||||
cropWidth: this.currentFrame.sourceSizeW,
|
||||
cropHeight: this.currentFrame.sourceSizeH
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} offset - Corner point defaults. Should not typically be modified.
|
||||
*/
|
||||
this.offset = new Phaser.Point;
|
||||
*/
|
||||
this.offset = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} center - A Point containing the center coordinate of the Sprite. Takes rotation and scale into account.
|
||||
@@ -665,7 +740,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
|
||||
/**
|
||||
* @property {number} health - Health value. Used in combination with damage() to allow for quick killing of Sprites.
|
||||
*/
|
||||
*/
|
||||
this.health = 1;
|
||||
|
||||
/**
|
||||
@@ -702,7 +777,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
/**
|
||||
* @property {Phaser.Point} cameraOffset - If this Sprite is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered.
|
||||
*/
|
||||
this.cameraOffset = new Phaser.Point;
|
||||
this.cameraOffset = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* You can crop the Sprites texture by modifying the crop properties. For example crop.width = 50 would set the Sprite to only render 50px wide.
|
||||
@@ -735,10 +810,12 @@ Phaser.Sprite.prototype.constructor = Phaser.Sprite;
|
||||
*/
|
||||
Phaser.Sprite.prototype.preUpdate = function() {
|
||||
|
||||
if (!this.exists)
|
||||
if (!this.exists || (this.group && !this.group.exists))
|
||||
{
|
||||
this.renderOrderID = -1;
|
||||
return;
|
||||
|
||||
// Skip children if not exists
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.lifespan > 0)
|
||||
@@ -748,7 +825,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
if (this.lifespan <= 0)
|
||||
{
|
||||
this.kill();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,6 +853,8 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
this.body.preUpdate();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -905,7 +984,7 @@ Phaser.Sprite.prototype.updateBounds = function() {
|
||||
|
||||
this.updateFrame = true;
|
||||
|
||||
if (this.inWorld == false)
|
||||
if (this.inWorld === false)
|
||||
{
|
||||
// Sprite WAS out of the screen, is it still?
|
||||
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
|
||||
@@ -921,7 +1000,7 @@ Phaser.Sprite.prototype.updateBounds = function() {
|
||||
// Sprite WAS in the screen, has it now left?
|
||||
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
|
||||
|
||||
if (this.inWorld == false)
|
||||
if (this.inWorld === false)
|
||||
{
|
||||
this.events.onOutOfBounds.dispatch(this);
|
||||
this._outOfBoundsFired = true;
|
||||
@@ -1013,6 +1092,11 @@ Phaser.Sprite.prototype.resetCrop = function() {
|
||||
*/
|
||||
Phaser.Sprite.prototype.postUpdate = function() {
|
||||
|
||||
if (this.key instanceof Phaser.BitmapData && this.key._dirty)
|
||||
{
|
||||
this.key.render();
|
||||
}
|
||||
|
||||
if (this.exists)
|
||||
{
|
||||
// The sprite is positioned in this call, after taking into consideration motion updates and collision
|
||||
@@ -1046,7 +1130,7 @@ Phaser.Sprite.prototype.postUpdate = function() {
|
||||
*
|
||||
* @method Phaser.Sprite#loadTexture
|
||||
* @memberof Phaser.Sprite
|
||||
* @param {string|Phaser.RenderTexture|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|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, BitmapData 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.Sprite.prototype.loadTexture = function (key, frame) {
|
||||
@@ -1057,6 +1141,11 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame) {
|
||||
{
|
||||
this.currentFrame = this.game.cache.getTextureFrame(key.name);
|
||||
}
|
||||
else if (key instanceof Phaser.BitmapData)
|
||||
{
|
||||
this.setTexture(key.texture);
|
||||
this.currentFrame = key.textureFrame;
|
||||
}
|
||||
else if (key instanceof PIXI.Texture)
|
||||
{
|
||||
this.currentFrame = frame;
|
||||
@@ -1435,9 +1524,11 @@ Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
|
||||
|
||||
set: function (value) {
|
||||
|
||||
console.log('inputEnabled', value, this.input);
|
||||
|
||||
if (value)
|
||||
{
|
||||
if (this.input.enabled == false)
|
||||
if (this.input.enabled === false)
|
||||
{
|
||||
this.input.start();
|
||||
}
|
||||
@@ -1474,7 +1565,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
|
||||
|
||||
<span class="jsdoc-message">
|
||||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
|
||||
on Thu Nov 07 2013 06:07:33 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
on Thu Nov 28 2013 15:56:25 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
||||
</span>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user