Updated docs for 1.1.2 release.

This commit is contained in:
photonstorm
2013-11-01 18:16:52 +00:00
parent eb95ce231b
commit 3e9777e6f4
150 changed files with 6188 additions and 2252 deletions
+127 -184
View File
@@ -58,10 +58,6 @@
<a href="Phaser.BitmapText.html">BitmapText</a>
</li>
<li>
<a href="Phaser.Bullet.html">Bullet</a>
</li>
<li>
<a href="Phaser.Button.html">Button</a>
</li>
@@ -525,6 +521,12 @@ Phaser.Sprite = function (game, x, y, key, frame) {
}
}
/**
* The rectangular area from the texture that will be rendered.
* @property {Phaser.Rectangle} textureRegion
*/
this.textureRegion = new Phaser.Rectangle(this.texture.frame.x, this.texture.frame.y, this.texture.frame.width, this.texture.frame.height);
/**
* The anchor sets the origin point of the texture.
* The default is 0,0 this means the textures origin is the top left
@@ -548,6 +550,11 @@ Phaser.Sprite = function (game, x, y, key, frame) {
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.
*/
this.world = new Phaser.Point(x, y);
/**
* Should this Sprite be automatically culled if out of range of the camera?
* A culled sprite has its renderable property set to 'false'.
@@ -579,15 +586,15 @@ Phaser.Sprite = function (game, x, y, key, frame) {
// Bounds check
left: null, right: null, top: null, bottom: null,
// delta cache
prevX: x, prevY: y,
// The previous calculated position
x: -1, y: -1,
// The actual scale values based on the worldTransform
scaleX: 1, scaleY: 1,
// cache scale check
realScaleX: 1, realScaleY: 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,
@@ -601,8 +608,6 @@ Phaser.Sprite = function (game, x, y, key, frame) {
// frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
frameID: -1, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
boundsX: 0, boundsY: 0,
// If this sprite visible to the camera (regardless of being set to visible or not)
cameraVisible: true,
@@ -690,6 +695,11 @@ Phaser.Sprite = function (game, x, y, key, frame) {
*/
this.fixedToCamera = false;
/**
* @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;
/**
* 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.
* The crop is only applied if you have set Sprite.cropEnabled to true.
@@ -704,6 +714,9 @@ Phaser.Sprite = function (game, x, y, key, frame) {
*/
this.cropEnabled = false;
this.updateCache();
this.updateBounds();
};
// Needed to keep the PIXI.Sprite constructor in the prototype chain (as the core pixi renderer uses an instanceof check sadly)
@@ -737,45 +750,21 @@ Phaser.Sprite.prototype.preUpdate = function() {
this._cache.dirty = false;
if (this.animations.update())
{
this._cache.dirty = true;
}
if (this.visible)
{
this.renderOrderID = this.game.world.currentRenderOrderID++;
}
this.prevX = this.x;
this.prevY = this.y;
this.updateCache();
this.updateAnimation();
if (this.cropEnabled)
{
this.updateCrop();
}
this.updateCrop();
// Re-run the camera visibility check
if (this._cache.dirty)
if (this._cache.dirty || this.world.x !== this._cache.prevX || this.world.y !== this._cache.prevY)
{
this.updateBounds();
this._cache.cameraVisible = Phaser.Rectangle.intersects(this.game.world.camera.screenView, this.bounds, 0);
if (this.autoCull == true)
{
// Won't get rendered but will still get its transform updated
this.renderable = this._cache.cameraVisible;
}
// Update our physics bounds
if (this.body)
{
this.body.updateBounds(this.center.x, this.center.y, this._cache.scaleX, this._cache.scaleY);
}
}
if (this.body)
@@ -783,7 +772,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
this.body.preUpdate();
}
}
};
/**
* Internal function called by preUpdate.
@@ -793,15 +782,22 @@ Phaser.Sprite.prototype.preUpdate = function() {
*/
Phaser.Sprite.prototype.updateCache = function() {
// |a c tx|
// |b d ty|
// |0 0 1|
this._cache.prevX = this.world.x;
this._cache.prevY = this.world.y;
if (this.worldTransform[1] != this._cache.i01 || this.worldTransform[3] != this._cache.i10)
if (this.fixedToCamera)
{
this._cache.a00 = this.worldTransform[0]; // scaleX a
this._cache.a01 = this.worldTransform[1]; // skewY c
this._cache.a10 = this.worldTransform[3]; // skewX b
this.x = this.game.camera.view.x + this.cameraOffset.x;
this.y = this.game.camera.view.y + this.cameraOffset.y;
}
this.world.setTo(this.game.camera.x + this.worldTransform[2], this.game.camera.y + this.worldTransform[5]);
if (this.worldTransform[1] != this._cache.i01 || this.worldTransform[3] != this._cache.i10 || this.worldTransform[0] != this._cache.a00 || this.worldTransform[41] != this._cache.a11)
{
this._cache.a00 = this.worldTransform[0]; // scaleX a |a c tx|
this._cache.a01 = this.worldTransform[1]; // skewY c |b d ty|
this._cache.a10 = this.worldTransform[3]; // skewX b |0 0 1|
this._cache.a11 = this.worldTransform[4]; // scaleY d
this._cache.i01 = this.worldTransform[1]; // skewY c (remains non-modified for input checks)
@@ -813,17 +809,16 @@ Phaser.Sprite.prototype.updateCache = function() {
this._cache.a01 *= -1;
this._cache.a10 *= -1;
this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
this._cache.dirty = true;
}
if (this.worldTransform[2] != this._cache.a02 || this.worldTransform[5] != this._cache.a12)
{
this._cache.a02 = this.worldTransform[2]; // translateX tx
this._cache.a12 = this.worldTransform[5]; // translateY ty
this._cache.dirty = true;
}
this._cache.a02 = this.worldTransform[2]; // translateX tx
this._cache.a12 = this.worldTransform[5]; // translateY ty
}
};
/**
* Internal function called by preUpdate.
@@ -833,26 +828,53 @@ Phaser.Sprite.prototype.updateCache = function() {
*/
Phaser.Sprite.prototype.updateAnimation = function() {
if (this.currentFrame && this.currentFrame.uuid != this._cache.frameID)
if (this.animations.update() || (this.currentFrame && this.currentFrame.uuid != this._cache.frameID))
{
this._cache.frameID = this.currentFrame.uuid;
this._cache.frameWidth = this.texture.frame.width;
this._cache.frameHeight = this.texture.frame.height;
this._cache.frameID = this.currentFrame.uuid;
this._cache.dirty = true;
}
if (this._cache.dirty && this.currentFrame)
{
this._cache.width = this.currentFrame.width;
this._cache.height = this.currentFrame.height;
this._cache.halfWidth = Math.floor(this._cache.width / 2);
this._cache.halfHeight = Math.floor(this._cache.height / 2);
this._cache.id = 1 / (this._cache.a00 * this._cache.a11 + this._cache.a01 * -this._cache.a10);
this._cache.idi = 1 / (this._cache.a00 * this._cache.a11 + this._cache.i01 * -this._cache.i10);
this._cache.dirty = true;
}
}
};
/**
* Internal function called by preUpdate.
*
* @method Phaser.Sprite#updateCrop
* @memberof Phaser.Sprite
*/
Phaser.Sprite.prototype.updateCrop = function() {
// This only runs if crop is enabled
if (this.cropEnabled && (this.crop.width != this._cache.cropWidth || this.crop.height != this._cache.cropHeight || this.crop.x != this._cache.cropX || this.crop.y != this._cache.cropY))
{
this.crop.floorAll();
this._cache.cropX = this.crop.x;
this._cache.cropY = this.crop.y;
this._cache.cropWidth = this.crop.width;
this._cache.cropHeight = this.crop.height;
this.texture.frame = this.crop;
this.texture.width = this.crop.width;
this.texture.height = this.crop.height;
this.texture.updateFrame = true;
PIXI.Texture.frameUpdates.push(this.texture);
}
};
/**
* Internal function called by preUpdate.
@@ -862,22 +884,13 @@ Phaser.Sprite.prototype.updateAnimation = function() {
*/
Phaser.Sprite.prototype.updateBounds = function() {
var sx = 1;
var sy = 1;
if (this.worldTransform[3] !== 0 || this.worldTransform[1] !== 0)
{
sx = this.scale.x;
sy = this.scale.y;
}
this.offset.setTo(this._cache.a02 - (this.anchor.x * this.width), this._cache.a12 - (this.anchor.y * this.height));
this.getLocalPosition(this.center, this.offset.x + (this.width / 2), this.offset.y + (this.height / 2), sx, sy);
this.getLocalPosition(this.topLeft, this.offset.x, this.offset.y, sx, sy);
this.getLocalPosition(this.topRight, this.offset.x + this.width, this.offset.y, sx, sy);
this.getLocalPosition(this.bottomLeft, this.offset.x, this.offset.y + this.height, sx, sy);
this.getLocalPosition(this.bottomRight, this.offset.x + this.width, this.offset.y + this.height, sx, sy);
this.getLocalPosition(this.center, this.offset.x + (this.width / 2), this.offset.y + (this.height / 2));
this.getLocalPosition(this.topLeft, this.offset.x, this.offset.y);
this.getLocalPosition(this.topRight, this.offset.x + this.width, this.offset.y);
this.getLocalPosition(this.bottomLeft, this.offset.x, this.offset.y + this.height);
this.getLocalPosition(this.bottomRight, this.offset.x + this.width, this.offset.y + this.height);
this._cache.left = Phaser.Math.min(this.topLeft.x, this.topRight.x, this.bottomLeft.x, this.bottomRight.x);
this._cache.right = Phaser.Math.max(this.topLeft.x, this.topRight.x, this.bottomLeft.x, this.bottomRight.x);
@@ -886,10 +899,6 @@ Phaser.Sprite.prototype.updateBounds = function() {
this.bounds.setTo(this._cache.left, this._cache.top, this._cache.right - this._cache.left, this._cache.bottom - this._cache.top);
// This is the coordinate the Sprite was at when the last bounds was created
this._cache.boundsX = this._cache.x;
this._cache.boundsY = this._cache.y;
this.updateFrame = true;
if (this.inWorld == false)
@@ -920,7 +929,21 @@ Phaser.Sprite.prototype.updateBounds = function() {
}
}
}
this._cache.cameraVisible = Phaser.Rectangle.intersects(this.game.world.camera.screenView, this.bounds, 0);
if (this.autoCull)
{
// Won't get rendered but will still get its transform updated
this.renderable = this._cache.cameraVisible;
}
// Update our physics bounds
if (this.body)
{
this.body.updateBounds(this.center.x, this.center.y, this._cache.scaleX, this._cache.scaleY);
}
};
/**
* Gets the local position of a coordinate relative to the Sprite, factoring in rotation and scale.
@@ -935,14 +958,14 @@ Phaser.Sprite.prototype.updateBounds = function() {
* @param {number} sy - Scale factor to be applied.
* @return {Phaser.Point} The translated point.
*/
Phaser.Sprite.prototype.getLocalPosition = function(p, x, y, sx, sy) {
Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) {
p.x = ((this._cache.a11 * this._cache.id * x + -this._cache.a01 * this._cache.id * y + (this._cache.a12 * this._cache.a01 - this._cache.a02 * this._cache.a11) * this._cache.id) * sx) + this._cache.a02;
p.y = ((this._cache.a00 * this._cache.id * y + -this._cache.a10 * this._cache.id * x + (-this._cache.a12 * this._cache.a00 + this._cache.a02 * this._cache.a10) * this._cache.id) * sy) + this._cache.a12;
p.x = ((this._cache.a11 * this._cache.id * x + -this._cache.a01 * this._cache.id * y + (this._cache.a12 * this._cache.a01 - this._cache.a02 * this._cache.a11) * this._cache.id) * this.scale.x) + this._cache.a02;
p.y = ((this._cache.a00 * this._cache.id * y + -this._cache.a10 * this._cache.id * x + (-this._cache.a12 * this._cache.a00 + this._cache.a02 * this._cache.a10) * this._cache.id) * this.scale.y) + this._cache.a12;
return p;
}
};
/**
* Gets the local unmodified position of a coordinate relative to the Sprite, factoring in rotation and scale.
@@ -957,47 +980,12 @@ Phaser.Sprite.prototype.getLocalPosition = function(p, x, y, sx, sy) {
*/
Phaser.Sprite.prototype.getLocalUnmodifiedPosition = function(p, gx, gy) {
var a00 = this.worldTransform[0], a01 = this.worldTransform[1], a02 = this.worldTransform[2],
a10 = this.worldTransform[3], a11 = this.worldTransform[4], a12 = this.worldTransform[5],
id = 1 / (a00 * a11 + a01 * -a10),
x = a11 * id * gx + -a01 * id * gy + (a12 * a01 - a02 * a11) * id,
y = a00 * id * gy + -a10 * id * gx + (-a12 * a00 + a02 * a10) * id;
p.x = x + (this.anchor.x * this._cache.width);
p.y = y + (this.anchor.y * this._cache.height);
p.x = (this._cache.a11 * this._cache.idi * gx + -this._cache.i01 * this._cache.idi * gy + (this._cache.a12 * this._cache.i01 - this._cache.a02 * this._cache.a11) * this._cache.idi) + (this.anchor.x * this._cache.width);
p.y = (this._cache.a00 * this._cache.idi * gy + -this._cache.i10 * this._cache.idi * gx + (-this._cache.a12 * this._cache.a00 + this._cache.a02 * this._cache.i10) * this._cache.idi) + (this.anchor.y * this._cache.height);
return p;
}
/**
* Internal function called by preUpdate.
*
* @method Phaser.Sprite#updateCrop
* @memberof Phaser.Sprite
*/
Phaser.Sprite.prototype.updateCrop = function() {
// This only runs if crop is enabled
if (this.crop.width != this._cache.cropWidth || this.crop.height != this._cache.cropHeight || this.crop.x != this._cache.cropX || this.crop.y != this._cache.cropY)
{
this.crop.floorAll();
this._cache.cropX = this.crop.x;
this._cache.cropY = this.crop.y;
this._cache.cropWidth = this.crop.width;
this._cache.cropHeight = this.crop.height;
this.texture.frame = this.crop;
this.texture.width = this.crop.width;
this.texture.height = this.crop.height;
this.texture.updateFrame = true;
PIXI.Texture.frameUpdates.push(this.texture);
}
}
};
/**
* Resets the Sprite.crop value back to the frame dimensions.
@@ -1011,7 +999,7 @@ Phaser.Sprite.prototype.resetCrop = function() {
this.texture.setFrame(this.crop);
this.cropEnabled = false;
}
};
/**
* Internal function called by the World postUpdate cycle.
@@ -1031,8 +1019,8 @@ Phaser.Sprite.prototype.postUpdate = function() {
if (this.fixedToCamera)
{
this._cache.x = this.game.camera.view.x + this.x;
this._cache.y = this.game.camera.view.y + this.y;
this._cache.x = this.game.camera.view.x + this.cameraOffset.x;
this._cache.y = this.game.camera.view.y + this.cameraOffset.y;
}
else
{
@@ -1040,14 +1028,13 @@ Phaser.Sprite.prototype.postUpdate = function() {
this._cache.y = this.y;
}
if (this.position.x != this._cache.x || this.position.y != this._cache.y)
{
this.position.x = this._cache.x;
this.position.y = this._cache.y;
}
this.world.setTo(this.game.camera.x + this.worldTransform[2], this.game.camera.y + this.worldTransform[5]);
this.position.x = this._cache.x;
this.position.y = this._cache.y;
}
}
};
/**
* Changes the Texture the Sprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache.
@@ -1101,51 +1088,7 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame) {
}
}
}
/**
* Returns the absolute delta x value.
*
* @method Phaser.Sprite#deltaAbsX
* @memberof Phaser.Sprite
* @return {number} The absolute delta value.
*/
Phaser.Sprite.prototype.deltaAbsX = function () {
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
}
/**
* Returns the absolute delta y value.
*
* @method Phaser.Sprite#deltaAbsY
* @memberof Phaser.Sprite
* @return {number} The absolute delta value.
*/
Phaser.Sprite.prototype.deltaAbsY = function () {
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
}
/**
* Returns the delta x value.
*
* @method Phaser.Sprite#deltaX
* @memberof Phaser.Sprite
* @return {number} The delta value.
*/
Phaser.Sprite.prototype.deltaX = function () {
return this.x - this.prevX;
}
/**
* Returns the delta y value.
*
* @method Phaser.Sprite#deltaY
* @memberof Phaser.Sprite
* @return {number} The delta value.
*/
Phaser.Sprite.prototype.deltaY = function () {
return this.y - this.prevY;
}
};
/**
* Moves the sprite so its center is located on the given x and y coordinates.
@@ -1163,7 +1106,7 @@ Phaser.Sprite.prototype.centerOn = function(x, y) {
this.y = y + (this.y - this.center.y);
return this;
}
};
/**
* Brings a 'dead' Sprite back to life, optionally giving it the health value specified.
@@ -1191,7 +1134,7 @@ Phaser.Sprite.prototype.revive = function(health) {
return this;
}
};
/**
* Kills a Sprite. A killed Sprite has its alive, exists and visible properties all set to false.
@@ -1216,7 +1159,7 @@ Phaser.Sprite.prototype.kill = function() {
return this;
}
};
/**
* Destroys the Sprite. This removes it from its parent group, destroys the input, event and animation handlers if present
@@ -1253,7 +1196,7 @@ Phaser.Sprite.prototype.destroy = function() {
this.game = null;
}
};
/**
* Damages the Sprite, this removes the given amount from the Sprites health property.
@@ -1278,7 +1221,7 @@ Phaser.Sprite.prototype.damage = function(amount) {
return this;
}
};
/**
* Resets the Sprite. This places the Sprite at the given x/y world coordinates and then
@@ -1315,7 +1258,7 @@ Phaser.Sprite.prototype.reset = function(x, y, health) {
return this;
}
};
/**
* Brings the Sprite to the top of the display list it is a child of. Sprites that are members of a Phaser.Group are only
@@ -1338,7 +1281,7 @@ Phaser.Sprite.prototype.bringToTop = function() {
return this;
}
};
/**
* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
@@ -1359,7 +1302,7 @@ Phaser.Sprite.prototype.play = function (name, frameRate, loop, killOnComplete)
return this.animations.play(name, frameRate, loop, killOnComplete);
}
}
};
/**
* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
@@ -1527,7 +1470,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 Fri Oct 25 2013 17:05:24 GMT+0100 (BST) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
on Fri Nov 01 2013 18:16:08 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
</div>