mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Merge branch 'dev' into multitexture-gl
This commit is contained in:
commit
4d09b31560
41 changed files with 8088 additions and 5989 deletions
24
README.md
24
README.md
|
@ -313,6 +313,8 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
|
|||
* Group.getRandomExists will return a random child from the Group that has exists set to true.
|
||||
* Group.getAll will return all children in the Group, or a section of the Group, with the optional ability to test if the child has a property matching the given value or not.
|
||||
* Group.iterate has a new `returnType`: `RETURN_ALL`. This allows you to return all children that pass the iteration test in an array.
|
||||
* The property `checkCollision.none` in the ArcadePhysics.Body class was available, but never used internally. It is now used and checked by the `separate` method. By setting `checkCollision.none = true` you can disable all collision and overlap checks on a Body, but still retain its motion updates (thanks @samme #2661)
|
||||
* Math.rotateToAngle takes two angles (in radians), and an interpolation value, and returns a new angle, based on the shortest rotational distance between the two.
|
||||
|
||||
### Updates
|
||||
|
||||
|
@ -326,20 +328,36 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
|
|||
* The Loader.headers object has a new property `requestedWith`. By default this is set to `false`, but it can be used to set the `X-Requested-With` header to `XMLHttpRequest` (or any other value you need). To enable this do `this.load.headers.requestedWith = 'XMLHttpRequest'` before adding anything to the Loader.
|
||||
* ScaleManager.hasPhaserSetFullScreen is a new boolean that identifies if the browser is in full screen mode or not, and if Phaser was the one that requested it. As it's possible to enter full screen mode outside of Phaser, and it then gets confused about what bounding parent to use.
|
||||
* Phaser.Tileset has a new property `lastgid` which is populated automatically by the TilemapParser when importing Tiled map data, or can be set manually if building your own tileset.
|
||||
* Stage will now check if `document.hidden` is available first, and if it is then never even check for the prefixed versions. This stops warnings like "mozHidden and mozVisibilityState are deprecated" in newer versions of browsers and retain backward compatibility (thanks @leopoldobrines7 #2656)
|
||||
* As a result of changes in #2573 Graphics objects were calling `updateLocalBounds` on any shape change, which could cause dramatic performances drops in Graphics heavy situations (#2618). Graphics objects now have a new flag `_boundsDirty` which is used to detect if the bounds have been invalidated, i.e. by a Graphics being cleared or drawn to. If this is set to true then `updateLocalBounds` is called once in the `postUpdate` method (thanks @pengchuan #2618)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* A Group with `inputEnableChildren` set would re-start the Input Handler on a Sprite, even if that handler had been disabled previously.
|
||||
* Weapon.autofire wouldn't fire after the first bullet, or until `fire` was called, neither of which are requirements. If you now set this boolean the Weapon will fire continuously until you toggle it back to false (thanks @alverLopez #2647)
|
||||
* ArcadePhysics.World.angleBetweenCenters now uses `centerX` and `centerY` properties to check for the angle between, instead of `center.x/y` as that property no longer exists (thanks @leopoldobrines7 #2654)
|
||||
* The Emitter.makeParticles `collide` argument didn't work, as a result of #2661, but is now properly respected thanks to that change (thanks @samme #2662)
|
||||
|
||||
### Pixi Updates
|
||||
|
||||
Please note that Phaser uses a custom build of Pixi and always has done. The following changes have been made to our custom build, not to Pixi in general.
|
||||
|
||||
*
|
||||
*
|
||||
*
|
||||
* This version contains significant fixes for `DisplayObject.getBounds` and `DisplayObjectContainer.getBounds`. The methods can now accept an optional argument `targetCoordinateSpace` which makes it much more flexible, allowing you to check the bounds against any target, not just local and global ones. If the `targetCoordinateSpace` is a valid DisplayObject:
|
||||
|
||||
- If it's a parent of the caller at some level it will return the bounds
|
||||
relative to it.
|
||||
- if it's not parenting the caller at all, it will get the global bounds of
|
||||
it, and the caller and will calculate the x and y bounds of the caller
|
||||
relative to the targetCoordinateSpace DisplayObject.
|
||||
|
||||
As a result this also fixes how empty Groups are treated when they have no other
|
||||
children except Groups. So now calculations are correct.
|
||||
* DisplayObjectContainer.contains(child) is a new method which determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself. This method is
|
||||
used in the new getBounds function.
|
||||
* Corrected DisplayObjects default `_bounds` rect from (0, 0, 1, 1) to (0, 0, 0, 0).
|
||||
* Thanks to @fmflame for his hard work on the above (#2639 #2627)
|
||||
* The methods `setStageReference` and `removeStageReference` have been removed from all Pixi classes. Objects no longer have `stage` properties, or references to the Stage object. This is because no reference to the Stage is required for any calculations, and Phaser can only have 1 Stage, so adding and removing references to it were superfluous actions.
|
||||
|
||||
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
36
build/custom/phaser-arcade-physics.min.js
vendored
36
build/custom/phaser-arcade-physics.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
24
build/custom/phaser-minimum.min.js
vendored
24
build/custom/phaser-minimum.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
30
build/custom/phaser-no-physics.min.js
vendored
30
build/custom/phaser-no-physics.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
30
build/custom/phaser-split.min.js
vendored
30
build/custom/phaser-split.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* Phaser - http://phaser.io
|
||||
*
|
||||
* v2.6.2 "Kore Springs" - Built: Mon Jul 18 2016 23:41:20
|
||||
* v2.6.2 "Kore Springs" - Built: Sat Jul 23 2016 15:05:21
|
||||
*
|
||||
* By Richard Davey http://www.photonstorm.com @photonstorm
|
||||
*
|
||||
|
@ -171,7 +171,7 @@ PIXI.defaultRenderOptions = {
|
|||
* @class PIXI.DisplayObject
|
||||
* @constructor
|
||||
*/
|
||||
PIXI.DisplayObject = function() {
|
||||
PIXI.DisplayObject = function () {
|
||||
|
||||
/**
|
||||
* The coordinates, in pixels, of this DisplayObject, relative to its parent container.
|
||||
|
@ -272,15 +272,6 @@ PIXI.DisplayObject = function() {
|
|||
*/
|
||||
this.parent = null;
|
||||
|
||||
/**
|
||||
* The stage that this DisplayObject is connected to.
|
||||
*
|
||||
* @property {PIXI.Stage} stage
|
||||
* @default
|
||||
* @readOnly
|
||||
*/
|
||||
this.stage = null;
|
||||
|
||||
/**
|
||||
* The multiplied alpha value of this DisplayObject. A value of 1 is fully opaque. A value of 0 is transparent.
|
||||
* This value is the calculated total, based on the alpha values of all parents of this DisplayObjects
|
||||
|
@ -382,7 +373,7 @@ PIXI.DisplayObject = function() {
|
|||
* @property {PIXI.Rectangle} _bounds - The cached bounds of this object.
|
||||
* @private
|
||||
*/
|
||||
this._bounds = new PIXI.Rectangle(0, 0, 1, 1);
|
||||
this._bounds = new PIXI.Rectangle(0, 0, 0, 0);
|
||||
|
||||
/**
|
||||
* @property {PIXI.Rectangle} _currentBounds - The most recently calculated bounds of this object.
|
||||
|
@ -417,8 +408,7 @@ PIXI.DisplayObject.prototype = {
|
|||
/**
|
||||
* Destroy this DisplayObject.
|
||||
*
|
||||
* Removes any cached sprites, sets renderable flag to false, and nulls references to the Stage, filters,
|
||||
* bounds and mask.
|
||||
* Removes any cached sprites, sets renderable flag to false, and nulls filters, bounds and mask.
|
||||
*
|
||||
* Also iteratively calls `destroy` on any children.
|
||||
*
|
||||
|
@ -440,7 +430,6 @@ PIXI.DisplayObject.prototype = {
|
|||
|
||||
this.hitArea = null;
|
||||
this.parent = null;
|
||||
this.stage = null;
|
||||
this.worldTransform = null;
|
||||
this.filterArea = null;
|
||||
this.renderable = false;
|
||||
|
@ -469,7 +458,7 @@ PIXI.DisplayObject.prototype = {
|
|||
* the new, updated, worldTransform property, along with the parent transform used.
|
||||
*
|
||||
* @method PIXI.DisplayObject#updateTransform
|
||||
* @param {PIXI.DisplayObject} [parent] - Optional parent to calculate this DisplayObjects transform from.
|
||||
* @param {PIXI.DisplayObjectContainer} [parent] - Optional parent to calculate this DisplayObjects transform from.
|
||||
* @return {PIXI.DisplayObject} - A reference to this DisplayObject.
|
||||
*/
|
||||
updateTransform: function (parent) {
|
||||
|
@ -567,21 +556,6 @@ PIXI.DisplayObject.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the root Stage object that this DisplayObject is connected to.
|
||||
*
|
||||
* @method PIXI.DisplayObject#setStageReference
|
||||
* @param {Phaser.Stage} stage - The stage that the object will have as its current stage reference
|
||||
* @return {PIXI.DisplayObject} - A reference to this DisplayObject.
|
||||
*/
|
||||
setStageReference: function (stage)
|
||||
{
|
||||
this.stage = stage;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* To be overridden by classes that require it.
|
||||
*
|
||||
|
@ -991,8 +965,8 @@ Object.defineProperties(PIXI.DisplayObject.prototype, {
|
|||
* @extends DisplayObject
|
||||
* @constructor
|
||||
*/
|
||||
PIXI.DisplayObjectContainer = function()
|
||||
{
|
||||
PIXI.DisplayObjectContainer = function () {
|
||||
|
||||
PIXI.DisplayObject.call(this);
|
||||
|
||||
/**
|
||||
|
@ -1017,69 +991,9 @@ PIXI.DisplayObjectContainer = function()
|
|||
|
||||
};
|
||||
|
||||
// constructor
|
||||
PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype );
|
||||
PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer;
|
||||
|
||||
/**
|
||||
* The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property width
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', {
|
||||
|
||||
get: function() {
|
||||
return this.scale.x * this.getLocalBounds().width;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
var width = this.getLocalBounds().width;
|
||||
|
||||
if (width !== 0)
|
||||
{
|
||||
this.scale.x = value / width;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scale.x = 1;
|
||||
}
|
||||
|
||||
this._width = value;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The height of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property height
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', {
|
||||
|
||||
get: function() {
|
||||
return this.scale.y * this.getLocalBounds().height;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
var height = this.getLocalBounds().height;
|
||||
|
||||
if (height !== 0)
|
||||
{
|
||||
this.scale.y = value / height;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scale.y = 1;
|
||||
}
|
||||
|
||||
this._height = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Adds a child to the container.
|
||||
*
|
||||
|
@ -1087,9 +1001,10 @@ Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', {
|
|||
* @param child {DisplayObject} The DisplayObject to add to the container
|
||||
* @return {DisplayObject} The child that was added.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.addChild = function(child)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.addChild = function (child) {
|
||||
|
||||
return this.addChildAt(child, this.children.length);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1100,11 +1015,11 @@ PIXI.DisplayObjectContainer.prototype.addChild = function(child)
|
|||
* @param index {Number} The index to place the child in
|
||||
* @return {DisplayObject} The child that was added.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
|
||||
{
|
||||
if(index >= 0 && index <= this.children.length)
|
||||
PIXI.DisplayObjectContainer.prototype.addChildAt = function (child, index) {
|
||||
|
||||
if (index >= 0 && index <= this.children.length)
|
||||
{
|
||||
if(child.parent)
|
||||
if (child.parent)
|
||||
{
|
||||
child.parent.removeChild(child);
|
||||
}
|
||||
|
@ -1113,14 +1028,13 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
|
|||
|
||||
this.children.splice(index, 0, child);
|
||||
|
||||
if(this.stage)child.setStageReference(this.stage);
|
||||
|
||||
return child;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Error(child + 'addChildAt: The index '+ index +' supplied is out of bounds ' + this.children.length);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1130,16 +1044,18 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
|
|||
* @param child {DisplayObject}
|
||||
* @param child2 {DisplayObject}
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2)
|
||||
{
|
||||
if(child === child2) {
|
||||
PIXI.DisplayObjectContainer.prototype.swapChildren = function (child, child2) {
|
||||
|
||||
if (child === child2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var index1 = this.getChildIndex(child);
|
||||
var index2 = this.getChildIndex(child2);
|
||||
|
||||
if(index1 < 0 || index2 < 0) {
|
||||
if (index1 < 0 || index2 < 0)
|
||||
{
|
||||
throw new Error('swapChildren: Both the supplied DisplayObjects must be a child of the caller.');
|
||||
}
|
||||
|
||||
|
@ -1155,14 +1071,17 @@ PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2)
|
|||
* @param child {DisplayObject} The DisplayObject instance to identify
|
||||
* @return {Number} The index position of the child display object to identify
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.getChildIndex = function(child)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.getChildIndex = function (child) {
|
||||
|
||||
var index = this.children.indexOf(child);
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
throw new Error('The supplied DisplayObject must be a child of the caller');
|
||||
}
|
||||
|
||||
return index;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1172,15 +1091,18 @@ PIXI.DisplayObjectContainer.prototype.getChildIndex = function(child)
|
|||
* @param child {DisplayObject} The child DisplayObject instance for which you want to change the index number
|
||||
* @param index {Number} The resulting index number for the child display object
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.setChildIndex = function(child, index)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.setChildIndex = function (child, index) {
|
||||
|
||||
if (index < 0 || index >= this.children.length)
|
||||
{
|
||||
throw new Error('The supplied index is out of bounds');
|
||||
}
|
||||
|
||||
var currentIndex = this.getChildIndex(child);
|
||||
|
||||
this.children.splice(currentIndex, 1); //remove from old position
|
||||
this.children.splice(index, 0, child); //add at new position
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1190,12 +1112,13 @@ PIXI.DisplayObjectContainer.prototype.setChildIndex = function(child, index)
|
|||
* @param index {Number} The index to get the child from
|
||||
* @return {DisplayObject} The child at the given index, if any.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.getChildAt = function(index)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.getChildAt = function (index) {
|
||||
|
||||
if (index < 0 || index >= this.children.length)
|
||||
{
|
||||
throw new Error('getChildAt: Supplied index '+ index +' does not exist in the child list, or the supplied DisplayObject must be a child of the caller');
|
||||
}
|
||||
|
||||
return this.children[index];
|
||||
|
||||
};
|
||||
|
@ -1207,12 +1130,17 @@ PIXI.DisplayObjectContainer.prototype.getChildAt = function(index)
|
|||
* @param child {DisplayObject} The DisplayObject to remove
|
||||
* @return {DisplayObject} The child that was removed.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
|
||||
{
|
||||
var index = this.children.indexOf( child );
|
||||
if(index === -1)return;
|
||||
PIXI.DisplayObjectContainer.prototype.removeChild = function (child) {
|
||||
|
||||
var index = this.children.indexOf(child);
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return this.removeChildAt( index );
|
||||
return this.removeChildAt(index);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1222,15 +1150,19 @@ PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
|
|||
* @param index {Number} The index to get the child from
|
||||
* @return {DisplayObject} The child that was removed.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.removeChildAt = function(index)
|
||||
{
|
||||
var child = this.getChildAt( index );
|
||||
if(this.stage)
|
||||
child.removeStageReference();
|
||||
PIXI.DisplayObjectContainer.prototype.removeChildAt = function (index) {
|
||||
|
||||
var child = this.getChildAt(index);
|
||||
|
||||
if (child)
|
||||
{
|
||||
child.parent = undefined;
|
||||
|
||||
this.children.splice(index, 1);
|
||||
}
|
||||
|
||||
child.parent = undefined;
|
||||
this.children.splice( index, 1 );
|
||||
return child;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1240,21 +1172,23 @@ PIXI.DisplayObjectContainer.prototype.removeChildAt = function(index)
|
|||
* @param beginIndex {Number} The beginning position. Default value is 0.
|
||||
* @param endIndex {Number} The ending position. Default value is size of the container.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endIndex)
|
||||
{
|
||||
var begin = beginIndex || 0;
|
||||
var end = typeof endIndex === 'number' ? endIndex : this.children.length;
|
||||
var range = end - begin;
|
||||
PIXI.DisplayObjectContainer.prototype.removeChildren = function (beginIndex, endIndex) {
|
||||
|
||||
if (range > 0 && range <= end)
|
||||
if (beginIndex === undefined) { beginIndex = 0; }
|
||||
if (endIndex === undefined) { endIndex = this.children.length; }
|
||||
|
||||
var range = endIndex - beginIndex;
|
||||
|
||||
if (range > 0 && range <= endIndex)
|
||||
{
|
||||
var removed = this.children.splice(begin, range);
|
||||
for (var i = 0; i < removed.length; i++) {
|
||||
|
||||
for (var i = 0; i < removed.length; i++)
|
||||
{
|
||||
var child = removed[i];
|
||||
if(this.stage)
|
||||
child.removeStageReference();
|
||||
child.parent = undefined;
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
else if (range === 0 && this.children.length === 0)
|
||||
|
@ -1265,6 +1199,7 @@ PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endI
|
|||
{
|
||||
throw new Error( 'removeChildren: Range Error, numeric values are outside the acceptable range' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -1273,8 +1208,8 @@ PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endI
|
|||
* @method updateTransform
|
||||
* @private
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.updateTransform = function()
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.updateTransform = function () {
|
||||
|
||||
if (!this.visible)
|
||||
{
|
||||
return;
|
||||
|
@ -1291,25 +1226,50 @@ PIXI.DisplayObjectContainer.prototype.updateTransform = function()
|
|||
{
|
||||
this.children[i].updateTransform();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// performance increase to avoid using call.. (10x faster)
|
||||
PIXI.DisplayObjectContainer.prototype.displayObjectContainerUpdateTransform = PIXI.DisplayObjectContainer.prototype.updateTransform;
|
||||
|
||||
/**
|
||||
* Retrieves the bounds of the displayObjectContainer as a rectangle. The bounds calculation takes all visible children into consideration.
|
||||
* Retrieves the global bounds of the displayObjectContainer as a rectangle. The bounds calculation takes all visible children into consideration.
|
||||
*
|
||||
* @method getBounds
|
||||
* @param {PIXI.DisplayObject|PIXI.Matrix} [targetCoordinateSpace] Returns a rectangle that defines the area of the display object relative to the coordinate system of the targetCoordinateSpace object.
|
||||
* @return {Rectangle} The rectangular bounding area
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.getBounds = function()
|
||||
{
|
||||
if (this.children.length === 0)
|
||||
{
|
||||
return PIXI.EmptyRectangle;
|
||||
PIXI.DisplayObjectContainer.prototype.getBounds = function (targetCoordinateSpace) {
|
||||
|
||||
var isTargetCoordinateSpaceDisplayObject = (targetCoordinateSpace && targetCoordinateSpace instanceof PIXI.DisplayObject);
|
||||
var isTargetCoordinateSpaceThisOrParent = true;
|
||||
|
||||
if (!isTargetCoordinateSpaceDisplayObject)
|
||||
{
|
||||
targetCoordinateSpace = this;
|
||||
}
|
||||
else if (targetCoordinateSpace instanceof PIXI.DisplayObjectContainer)
|
||||
{
|
||||
isTargetCoordinateSpaceThisOrParent = targetCoordinateSpace.contains(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
isTargetCoordinateSpaceThisOrParent = false;
|
||||
}
|
||||
|
||||
this.updateTransform();
|
||||
var i;
|
||||
|
||||
if (isTargetCoordinateSpaceDisplayObject)
|
||||
{
|
||||
var matrixCache = targetCoordinateSpace.worldTransform;
|
||||
|
||||
targetCoordinateSpace.worldTransform = PIXI.identityMatrix;
|
||||
|
||||
for (i = 0; i < targetCoordinateSpace.children.length; i++)
|
||||
{
|
||||
targetCoordinateSpace.children[i].updateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
var minX = Infinity;
|
||||
var minY = Infinity;
|
||||
|
@ -1323,10 +1283,10 @@ PIXI.DisplayObjectContainer.prototype.getBounds = function()
|
|||
|
||||
var childVisible = false;
|
||||
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
for (i = 0; i < this.children.length; i++)
|
||||
{
|
||||
var child = this.children[i];
|
||||
|
||||
|
||||
if (!child.visible)
|
||||
{
|
||||
continue;
|
||||
|
@ -1335,30 +1295,98 @@ PIXI.DisplayObjectContainer.prototype.getBounds = function()
|
|||
childVisible = true;
|
||||
|
||||
childBounds = this.children[i].getBounds();
|
||||
|
||||
minX = minX < childBounds.x ? minX : childBounds.x;
|
||||
minY = minY < childBounds.y ? minY : childBounds.y;
|
||||
|
||||
minX = (minX < childBounds.x) ? minX : childBounds.x;
|
||||
minY = (minY < childBounds.y) ? minY : childBounds.y;
|
||||
|
||||
childMaxX = childBounds.width + childBounds.x;
|
||||
childMaxY = childBounds.height + childBounds.y;
|
||||
|
||||
maxX = maxX > childMaxX ? maxX : childMaxX;
|
||||
maxY = maxY > childMaxY ? maxY : childMaxY;
|
||||
}
|
||||
|
||||
if (!childVisible)
|
||||
{
|
||||
return PIXI.EmptyRectangle;
|
||||
maxX = (maxX > childMaxX) ? maxX : childMaxX;
|
||||
maxY = (maxY > childMaxY) ? maxY : childMaxY;
|
||||
}
|
||||
|
||||
var bounds = this._bounds;
|
||||
|
||||
if (!childVisible)
|
||||
{
|
||||
bounds = new PIXI.Rectangle();
|
||||
|
||||
var w0 = bounds.x;
|
||||
var w1 = bounds.width + bounds.x;
|
||||
|
||||
var h0 = bounds.y;
|
||||
var h1 = bounds.height + bounds.y;
|
||||
|
||||
var worldTransform = this.worldTransform;
|
||||
|
||||
var a = worldTransform.a;
|
||||
var b = worldTransform.b;
|
||||
var c = worldTransform.c;
|
||||
var d = worldTransform.d;
|
||||
var tx = worldTransform.tx;
|
||||
var ty = worldTransform.ty;
|
||||
|
||||
var x1 = a * w1 + c * h1 + tx;
|
||||
var y1 = d * h1 + b * w1 + ty;
|
||||
|
||||
var x2 = a * w0 + c * h1 + tx;
|
||||
var y2 = d * h1 + b * w0 + ty;
|
||||
|
||||
var x3 = a * w0 + c * h0 + tx;
|
||||
var y3 = d * h0 + b * w0 + ty;
|
||||
|
||||
var x4 = a * w1 + c * h0 + tx;
|
||||
var y4 = d * h0 + b * w1 + ty;
|
||||
|
||||
maxX = x1;
|
||||
maxY = y1;
|
||||
|
||||
minX = x1;
|
||||
minY = y1;
|
||||
|
||||
minX = x2 < minX ? x2 : minX;
|
||||
minX = x3 < minX ? x3 : minX;
|
||||
minX = x4 < minX ? x4 : minX;
|
||||
|
||||
minY = y2 < minY ? y2 : minY;
|
||||
minY = y3 < minY ? y3 : minY;
|
||||
minY = y4 < minY ? y4 : minY;
|
||||
|
||||
maxX = x2 > maxX ? x2 : maxX;
|
||||
maxX = x3 > maxX ? x3 : maxX;
|
||||
maxX = x4 > maxX ? x4 : maxX;
|
||||
|
||||
maxY = y2 > maxY ? y2 : maxY;
|
||||
maxY = y3 > maxY ? y3 : maxY;
|
||||
maxY = y4 > maxY ? y4 : maxY;
|
||||
}
|
||||
|
||||
bounds.x = minX;
|
||||
bounds.y = minY;
|
||||
bounds.width = maxX - minX;
|
||||
bounds.height = maxY - minY;
|
||||
|
||||
if (isTargetCoordinateSpaceDisplayObject)
|
||||
{
|
||||
targetCoordinateSpace.worldTransform = matrixCache;
|
||||
|
||||
for (i = 0; i < targetCoordinateSpace.children.length; i++)
|
||||
{
|
||||
targetCoordinateSpace.children[i].updateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isTargetCoordinateSpaceThisOrParent)
|
||||
{
|
||||
var targetCoordinateSpaceBounds = targetCoordinateSpace.getBounds();
|
||||
|
||||
bounds.x -= targetCoordinateSpaceBounds.x;
|
||||
bounds.y -= targetCoordinateSpaceBounds.y;
|
||||
}
|
||||
|
||||
return bounds;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1367,58 +1395,33 @@ PIXI.DisplayObjectContainer.prototype.getBounds = function()
|
|||
* @method getLocalBounds
|
||||
* @return {Rectangle} The rectangular bounding area
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.getLocalBounds = function()
|
||||
{
|
||||
var matrixCache = this.worldTransform;
|
||||
PIXI.DisplayObjectContainer.prototype.getLocalBounds = function () {
|
||||
|
||||
this.worldTransform = PIXI.identityMatrix;
|
||||
return this.getBounds(this.parent);
|
||||
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].updateTransform();
|
||||
}
|
||||
|
||||
var bounds = this.getBounds();
|
||||
|
||||
this.worldTransform = matrixCache;
|
||||
|
||||
for (i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].updateTransform();
|
||||
}
|
||||
|
||||
return bounds;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the containers Stage reference. This is the Stage that this object, and all of its children, is connected to.
|
||||
*
|
||||
* @method setStageReference
|
||||
* @param stage {Stage} the stage that the container will have as its current stage reference
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.setStageReference = function(stage)
|
||||
{
|
||||
this.stage = stage;
|
||||
|
||||
for (var i=0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].setStageReference(stage)
|
||||
}
|
||||
};
|
||||
* Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself.
|
||||
*
|
||||
* @method contains
|
||||
* @param {DisplayObject} child
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.contains = function (child) {
|
||||
|
||||
/**
|
||||
* Removes the current stage reference from the container and all of its children.
|
||||
*
|
||||
* @method removeStageReference
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.removeStageReference = function()
|
||||
{
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
if (!child)
|
||||
{
|
||||
this.children[i].removeStageReference();
|
||||
return false;
|
||||
}
|
||||
else if (child === this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.contains(child.parent);
|
||||
}
|
||||
|
||||
this.stage = null;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1428,9 +1431,12 @@ PIXI.DisplayObjectContainer.prototype.removeStageReference = function()
|
|||
* @param renderSession {RenderSession}
|
||||
* @private
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype._renderWebGL = function(renderSession)
|
||||
{
|
||||
if (!this.visible || this.alpha <= 0) return;
|
||||
PIXI.DisplayObjectContainer.prototype._renderWebGL = function (renderSession) {
|
||||
|
||||
if (!this.visible || this.alpha <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._cacheAsBitmap)
|
||||
{
|
||||
|
@ -1477,6 +1483,7 @@ PIXI.DisplayObjectContainer.prototype._renderWebGL = function(renderSession)
|
|||
this.children[i]._renderWebGL(renderSession);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1486,9 +1493,12 @@ PIXI.DisplayObjectContainer.prototype._renderWebGL = function(renderSession)
|
|||
* @param renderSession {RenderSession}
|
||||
* @private
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype._renderCanvas = function(renderSession)
|
||||
{
|
||||
if (this.visible === false || this.alpha === 0) return;
|
||||
PIXI.DisplayObjectContainer.prototype._renderCanvas = function (renderSession) {
|
||||
|
||||
if (this.visible === false || this.alpha === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._cacheAsBitmap)
|
||||
{
|
||||
|
@ -1513,6 +1523,66 @@ PIXI.DisplayObjectContainer.prototype._renderCanvas = function(renderSession)
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property width
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', {
|
||||
|
||||
get: function() {
|
||||
return this.getLocalBounds().width;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
var width = this.getLocalBounds().width;
|
||||
|
||||
if (width !== 0)
|
||||
{
|
||||
this.scale.x = value / width;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scale.x = 1;
|
||||
}
|
||||
|
||||
this._width = value;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The height of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property height
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', {
|
||||
|
||||
get: function() {
|
||||
return this.getLocalBounds().height;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
var height = this.getLocalBounds().height;
|
||||
|
||||
if (height !== 0)
|
||||
{
|
||||
this.scale.y = value / height;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scale.y = 1;
|
||||
}
|
||||
|
||||
this._height = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
|
@ -1524,14 +1594,9 @@ PIXI.DisplayObjectContainer.prototype._renderCanvas = function(renderSession)
|
|||
* @extends DisplayObjectContainer
|
||||
* @constructor
|
||||
* @param texture {Texture} The texture for this sprite
|
||||
*
|
||||
* A sprite can be created directly from an image like this :
|
||||
* var sprite = new PIXI.Sprite.fromImage('assets/image.png');
|
||||
* yourStage.addChild(sprite);
|
||||
* then obviously don't forget to add it to the stage you have already created
|
||||
*/
|
||||
PIXI.Sprite = function(texture)
|
||||
{
|
||||
PIXI.Sprite = function (texture) {
|
||||
|
||||
PIXI.DisplayObjectContainer.call(this);
|
||||
|
||||
/**
|
||||
|
@ -1611,7 +1676,8 @@ PIXI.Sprite = function(texture)
|
|||
this.blendMode = PIXI.blendModes.NORMAL;
|
||||
|
||||
/**
|
||||
* The shader that will be used to render the texture to the stage. Set to null to remove a current shader.
|
||||
* The shader that will be used to render this Sprite.
|
||||
* Set to null to remove a current shader.
|
||||
*
|
||||
* @property shader
|
||||
* @type AbstractFilter
|
||||
|
@ -2018,8 +2084,6 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession, matrix)
|
|||
|
||||
var container = new PIXI.SpriteBatch();
|
||||
|
||||
stage.addChild(container);
|
||||
|
||||
for(var i = 0; i < 100; i++)
|
||||
{
|
||||
var sprite = new PIXI.Sprite.fromImage("myImage.png");
|
||||
|
@ -3478,20 +3542,21 @@ PIXI.ComplexPrimitiveShader.prototype.destroy = function()
|
|||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
|
||||
PIXI.glContexts = []; // this is where we store the webGL contexts for easy access.
|
||||
// this is where we store the webGL contexts for easy access.
|
||||
PIXI.glContexts = [];
|
||||
PIXI.instances = [];
|
||||
|
||||
/**
|
||||
* The WebGLRenderer draws the stage and all its content onto a webGL enabled canvas. This renderer
|
||||
* should be used for browsers that support webGL. This Render works by automatically managing webGLBatchs.
|
||||
* So no need for Sprite Batches or Sprite Clouds.
|
||||
* Don't forget to add the view to your DOM or you will not see anything :)
|
||||
* The WebGLRenderer draws the stage and all its content onto a WebGL enabled canvas.
|
||||
* This renderer should be used for browsers that support WebGL.
|
||||
* This renderer works by automatically managing WebGL Batches, so there is no need for
|
||||
* Sprite Batches or Sprite Clouds.
|
||||
*
|
||||
* @class WebGLRenderer
|
||||
* @constructor
|
||||
* @param game {Phaser.Game} A reference to the Phaser Game instance
|
||||
*/
|
||||
PIXI.WebGLRenderer = function(game) {
|
||||
PIXI.WebGLRenderer = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the Phaser Game instance.
|
||||
|
@ -3717,38 +3782,43 @@ PIXI.WebGLRenderer.prototype.initContext = function()
|
|||
};
|
||||
|
||||
/**
|
||||
* Renders the stage to its webGL view
|
||||
* Renders the DisplayObjectContainer, usually the Phaser.Stage, to the WebGL enabled canvas.
|
||||
*
|
||||
* @method render
|
||||
* @param stage {Stage} the Stage element to be rendered
|
||||
* @param root {Phaser.Stage|PIXI.DisplayObjectContainer} The root element to be rendered.
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.render = function(stage)
|
||||
{
|
||||
// no point rendering if our context has been blown up!
|
||||
PIXI.WebGLRenderer.prototype.render = function (root) {
|
||||
|
||||
if (this.contextLost)
|
||||
{
|
||||
// No point rendering if the context is lost.
|
||||
return;
|
||||
}
|
||||
|
||||
var gl = this.gl;
|
||||
|
||||
// -- Does this need to be set every frame? -- //
|
||||
gl.viewport(0, 0, this.width, this.height);
|
||||
|
||||
// make sure we are bound to the main frame buffer
|
||||
// Bind the Frame Buffer
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
|
||||
// Clear it
|
||||
if (this.game.clearBeforeRender)
|
||||
{
|
||||
gl.clearColor(stage._bgColor.r, stage._bgColor.g, stage._bgColor.b, stage._bgColor.a);
|
||||
var color = this.game.stage._bgColor;
|
||||
|
||||
gl.clearColor(color.r, color.g, color.b, color.a);
|
||||
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
// Apply Camera Shake
|
||||
this.offset.x = this.game.camera._shake.x;
|
||||
this.offset.y = this.game.camera._shake.y;
|
||||
|
||||
this.renderDisplayObject(stage, this.projection);
|
||||
// Let the magic begin ...
|
||||
this.renderDisplayObject(root, this.projection);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -3759,8 +3829,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
|
|||
* @param projection {Point} The projection
|
||||
* @param buffer {Array} a standard WebGL buffer
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, projection, buffer, matrix)
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, projection, buffer, matrix) {
|
||||
|
||||
this.renderSession.blendModeManager.setBlendMode(PIXI.blendModes.NORMAL);
|
||||
|
||||
// reset the render session data..
|
||||
|
@ -3786,6 +3856,7 @@ PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, proje
|
|||
|
||||
// finish the sprite batch
|
||||
this.spriteBatch.end();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -3795,15 +3866,18 @@ PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, proje
|
|||
* @param width {Number} the new width of the webGL view
|
||||
* @param height {Number} the new height of the webGL view
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.resize = function(width, height)
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.resize = function (width, height) {
|
||||
|
||||
this.width = width * this.resolution;
|
||||
this.height = height * this.resolution;
|
||||
|
||||
this.view.width = this.width;
|
||||
this.view.height = this.height;
|
||||
|
||||
if (this.autoResize) {
|
||||
// TODO - This probably needs removing, along with the property
|
||||
// as it will conflict with the ScaleManager
|
||||
if (this.autoResize)
|
||||
{
|
||||
this.view.style.width = this.width / this.resolution + 'px';
|
||||
this.view.style.height = this.height / this.resolution + 'px';
|
||||
}
|
||||
|
@ -3812,17 +3886,18 @@ PIXI.WebGLRenderer.prototype.resize = function(width, height)
|
|||
|
||||
this.projection.x = this.width / 2 / this.resolution;
|
||||
this.projection.y = -this.height / 2 / this.resolution;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates and Creates a WebGL texture for the renderers context.
|
||||
* Updates and creates a WebGL texture for the renderers context.
|
||||
*
|
||||
* @method updateTexture
|
||||
* @param texture {Texture} the texture to update
|
||||
* @return {boolean} True if the texture was successfully bound, otherwise false.
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.updateTexture = function (texture) {
|
||||
|
||||
if (!texture.hasLoaded)
|
||||
{
|
||||
return false;
|
||||
|
@ -3866,7 +3941,6 @@ PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
|
|||
|
||||
texture._dirty[gl.id] = false;
|
||||
|
||||
// return texture._glTextures[gl.id];
|
||||
return true;
|
||||
|
||||
};
|
||||
|
@ -3876,8 +3950,8 @@ PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
|
|||
*
|
||||
* @method destroy
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.destroy = function()
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.destroy = function () {
|
||||
|
||||
PIXI.glContexts[this.glContextId] = null;
|
||||
|
||||
this.projection = null;
|
||||
|
@ -3901,6 +3975,7 @@ PIXI.WebGLRenderer.prototype.destroy = function()
|
|||
PIXI.instances[this.glContextId] = null;
|
||||
|
||||
PIXI.WebGLRenderer.glContextId--;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -3908,8 +3983,8 @@ PIXI.WebGLRenderer.prototype.destroy = function()
|
|||
*
|
||||
* @method mapBlendModes
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.mapBlendModes = function()
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.mapBlendModes = function () {
|
||||
|
||||
var gl = this.gl;
|
||||
|
||||
if (!PIXI.blendModesWebGL)
|
||||
|
@ -3937,6 +4012,7 @@ PIXI.WebGLRenderer.prototype.mapBlendModes = function()
|
|||
|
||||
PIXI.blendModesWebGL = b;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
PIXI.WebGLRenderer.glContextId = 0;
|
||||
|
@ -6708,12 +6784,12 @@ PIXI.CanvasRenderer = function (game) {
|
|||
PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer;
|
||||
|
||||
/**
|
||||
* Renders the Stage to this canvas view
|
||||
* Renders the DisplayObjectContainer, usually the Phaser.Stage, to this canvas view.
|
||||
*
|
||||
* @method render
|
||||
* @param stage {Stage} the Stage element to be rendered
|
||||
* @param root {Phaser.Stage|PIXI.DisplayObjectContainer} The root element to be rendered.
|
||||
*/
|
||||
PIXI.CanvasRenderer.prototype.render = function (stage) {
|
||||
PIXI.CanvasRenderer.prototype.render = function (root) {
|
||||
|
||||
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
|
||||
|
@ -6737,14 +6813,14 @@ PIXI.CanvasRenderer.prototype.render = function (stage) {
|
|||
{
|
||||
this.context.clearRect(0, 0, this.width, this.height);
|
||||
}
|
||||
else
|
||||
else if (root._bgColor)
|
||||
{
|
||||
this.context.fillStyle = stage._bgColor.rgba;
|
||||
this.context.fillStyle = root._bgColor.rgba;
|
||||
this.context.fillRect(0, 0, this.width , this.height);
|
||||
}
|
||||
}
|
||||
|
||||
this.renderDisplayObject(stage);
|
||||
this.renderDisplayObject(root);
|
||||
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
6
build/custom/pixi.min.js
vendored
6
build/custom/pixi.min.js
vendored
File diff suppressed because one or more lines are too long
3356
build/phaser.js
3356
build/phaser.js
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
40
build/phaser.min.js
vendored
40
build/phaser.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -15,7 +15,7 @@ var Phaser = Phaser || {
|
|||
* @constant
|
||||
* @type {string}
|
||||
*/
|
||||
VERSION: '2.7.0 Beta 2',
|
||||
VERSION: '2.7.0 Beta 4',
|
||||
|
||||
/**
|
||||
* An array of Phaser game instances.
|
||||
|
|
|
@ -226,7 +226,11 @@ Phaser.Stage.prototype.updateTransform = function () {
|
|||
*/
|
||||
Phaser.Stage.prototype.checkVisibility = function () {
|
||||
|
||||
if (document.webkitHidden !== undefined)
|
||||
if (document.hidden !== undefined)
|
||||
{
|
||||
this._hiddenVar = 'visibilitychange';
|
||||
}
|
||||
else if (document.webkitHidden !== undefined)
|
||||
{
|
||||
this._hiddenVar = 'webkitvisibilitychange';
|
||||
}
|
||||
|
@ -238,10 +242,6 @@ Phaser.Stage.prototype.checkVisibility = function () {
|
|||
{
|
||||
this._hiddenVar = 'msvisibilitychange';
|
||||
}
|
||||
else if (document.hidden !== undefined)
|
||||
{
|
||||
this._hiddenVar = 'visibilitychange';
|
||||
}
|
||||
else
|
||||
{
|
||||
this._hiddenVar = null;
|
||||
|
|
|
@ -114,6 +114,28 @@ Phaser.Graphics.prototype.preUpdate = function () {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Automatically called by World
|
||||
* @method Phaser.Graphics.prototype.postUpdate
|
||||
*/
|
||||
Phaser.Graphics.prototype.postUpdate = function () {
|
||||
|
||||
Phaser.Component.PhysicsBody.postUpdate.call(this);
|
||||
Phaser.Component.FixedToCamera.postUpdate.call(this);
|
||||
|
||||
if (this._boundsDirty)
|
||||
{
|
||||
this.updateLocalBounds();
|
||||
this._boundsDirty = false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].postUpdate();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroy this Graphics instance.
|
||||
*
|
||||
|
|
|
@ -320,6 +320,57 @@ Phaser.Math = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Rotates currentAngle towards targetAngle, taking the shortest rotation distance.
|
||||
* The lerp argument is the amount to rotate by in this call.
|
||||
*
|
||||
* @method Phaser.Math#rotateToAngle
|
||||
* @param {number} currentAngle - The current angle, in radians.
|
||||
* @param {number} targetAngle - The target angle to rotate to, in radians.
|
||||
* @param {number} [lerp=0.05] - The lerp value to add to the current angle.
|
||||
* @return {number} The adjusted angle.
|
||||
*/
|
||||
rotateToAngle: function (currentAngle, targetAngle, lerp) {
|
||||
|
||||
if (lerp === undefined) { lerp = 0.05; }
|
||||
|
||||
if (currentAngle === targetAngle)
|
||||
{
|
||||
return currentAngle;
|
||||
}
|
||||
|
||||
if (Math.abs(targetAngle - currentAngle) <= lerp || Math.abs(targetAngle - currentAngle) >= (Phaser.Math.PI2 - lerp))
|
||||
{
|
||||
currentAngle = targetAngle;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Math.abs(targetAngle - currentAngle) > Math.PI)
|
||||
{
|
||||
if (targetAngle < currentAngle)
|
||||
{
|
||||
targetAngle += Phaser.Math.PI2;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetAngle -= Phaser.Math.PI2;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetAngle > currentAngle)
|
||||
{
|
||||
currentAngle += lerp;
|
||||
}
|
||||
else if (targetAngle < currentAngle)
|
||||
{
|
||||
currentAngle -= lerp;
|
||||
}
|
||||
}
|
||||
|
||||
return currentAngle;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Find the angle of a segment from (x1, y1) -> (x2, y2).
|
||||
*
|
||||
|
|
|
@ -363,6 +363,8 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
|||
/**
|
||||
* Set the checkCollision properties to control which directions collision is processed for this Body.
|
||||
* For example checkCollision.up = false means it won't collide when the collision happened while moving up.
|
||||
* If you need to disable a Body entirely, use `body.enable = false`, this will also disable motion.
|
||||
* If you need to disable just collision and/or overlap checks, but retain motion, set `checkCollision.none = true`.
|
||||
* @property {object} checkCollision - An object containing allowed collision.
|
||||
*/
|
||||
this.checkCollision = { none: false, any: true, up: true, down: true, left: true, right: true };
|
||||
|
|
|
@ -33,14 +33,15 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
|
|||
*/
|
||||
collideSpriteVsTilemapLayer: function (sprite, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly) {
|
||||
|
||||
if (!sprite.body)
|
||||
// Before we even do this, is the sprite outside the layer bounds?
|
||||
if (!sprite.body || sprite.body.bottom < tilemapLayer.y || sprite.body.top > tilemapLayer.bottom || sprite.body.right < tilemapLayer.x || sprite.body.x > tilemapLayer.right)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var mapData = tilemapLayer.getTiles(
|
||||
sprite.body.position.x - sprite.body.tilePadding.x,
|
||||
sprite.body.position.y - sprite.body.tilePadding.y,
|
||||
(sprite.body.position.x - sprite.body.tilePadding.x) - tilemapLayer.offsetX,
|
||||
(sprite.body.position.y - sprite.body.tilePadding.y) - tilemapLayer.offsetY,
|
||||
sprite.body.width + sprite.body.tilePadding.x,
|
||||
sprite.body.height + sprite.body.tilePadding.y,
|
||||
false, false);
|
||||
|
@ -129,8 +130,8 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
|
|||
return false;
|
||||
}
|
||||
|
||||
var tilemapLayerOffsetX = (!tilemapLayer.fixedToCamera) ? tilemapLayer.position.x : 0;
|
||||
var tilemapLayerOffsetY = (!tilemapLayer.fixedToCamera) ? tilemapLayer.position.y : 0;
|
||||
var tilemapLayerOffsetX = tilemapLayer.offsetX;
|
||||
var tilemapLayerOffsetY = tilemapLayer.offsetY;
|
||||
|
||||
// We re-check for collision in case body was separated in a previous step
|
||||
if (!tile.intersects((body.position.x - tilemapLayerOffsetX), (body.position.y - tilemapLayerOffsetY), (body.right - tilemapLayerOffsetX), (body.bottom - tilemapLayerOffsetY)))
|
||||
|
@ -152,7 +153,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
|
|||
// If it returns true then we can carry on, otherwise we should abort.
|
||||
return false;
|
||||
}
|
||||
else if (typeof tile.layer.callbacks !== 'undefined' && tile.layer.callbacks[tile.index] && !tile.layer.callbacks[tile.index].callback.call(tile.layer.callbacks[tile.index].callbackContext, body.sprite, tile))
|
||||
else if (tile.layer.callbacks !== undefined && tile.layer.callbacks[tile.index] && !tile.layer.callbacks[tile.index].callback.call(tile.layer.callbacks[tile.index].callbackContext, body.sprite, tile))
|
||||
{
|
||||
// If it returns true then we can carry on, otherwise we should abort.
|
||||
return false;
|
||||
|
@ -242,7 +243,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
|
|||
tileCheckX: function (body, tile, tilemapLayer) {
|
||||
|
||||
var ox = 0;
|
||||
var tilemapLayerOffsetX = (!tilemapLayer.fixedToCamera) ? tilemapLayer.position.x : 0;
|
||||
var tilemapLayerOffsetX = tilemapLayer.offsetX;
|
||||
|
||||
if (body.deltaX() < 0 && !body.blocked.left && tile.collideRight && body.checkCollision.left)
|
||||
{
|
||||
|
@ -300,7 +301,7 @@ Phaser.Physics.Arcade.TilemapCollision.prototype = {
|
|||
tileCheckY: function (body, tile, tilemapLayer) {
|
||||
|
||||
var oy = 0;
|
||||
var tilemapLayerOffsetY = (!tilemapLayer.fixedToCamera) ? tilemapLayer.position.y : 0;
|
||||
var tilemapLayerOffsetY = tilemapLayer.offsetY;
|
||||
|
||||
if (body.deltaY() < 0 && !body.blocked.up && tile.collideDown && body.checkCollision.up)
|
||||
{
|
||||
|
|
|
@ -947,7 +947,12 @@ Phaser.Physics.Arcade.prototype = {
|
|||
*/
|
||||
separate: function (body1, body2, processCallback, callbackContext, overlapOnly) {
|
||||
|
||||
if (!body1.enable || !body2.enable || !this.intersects(body1, body2))
|
||||
if (
|
||||
!body1.enable ||
|
||||
!body2.enable ||
|
||||
body1.checkCollision.none ||
|
||||
body2.checkCollision.none ||
|
||||
!this.intersects(body1, body2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* @class PIXI.DisplayObject
|
||||
* @constructor
|
||||
*/
|
||||
PIXI.DisplayObject = function() {
|
||||
PIXI.DisplayObject = function () {
|
||||
|
||||
/**
|
||||
* The coordinates, in pixels, of this DisplayObject, relative to its parent container.
|
||||
|
@ -116,15 +116,6 @@ PIXI.DisplayObject = function() {
|
|||
*/
|
||||
this.parent = null;
|
||||
|
||||
/**
|
||||
* The stage that this DisplayObject is connected to.
|
||||
*
|
||||
* @property {PIXI.Stage} stage
|
||||
* @default
|
||||
* @readOnly
|
||||
*/
|
||||
this.stage = null;
|
||||
|
||||
/**
|
||||
* The multiplied alpha value of this DisplayObject. A value of 1 is fully opaque. A value of 0 is transparent.
|
||||
* This value is the calculated total, based on the alpha values of all parents of this DisplayObjects
|
||||
|
@ -226,7 +217,7 @@ PIXI.DisplayObject = function() {
|
|||
* @property {PIXI.Rectangle} _bounds - The cached bounds of this object.
|
||||
* @private
|
||||
*/
|
||||
this._bounds = new PIXI.Rectangle(0, 0, 1, 1);
|
||||
this._bounds = new PIXI.Rectangle(0, 0, 0, 0);
|
||||
|
||||
/**
|
||||
* @property {PIXI.Rectangle} _currentBounds - The most recently calculated bounds of this object.
|
||||
|
@ -261,8 +252,7 @@ PIXI.DisplayObject.prototype = {
|
|||
/**
|
||||
* Destroy this DisplayObject.
|
||||
*
|
||||
* Removes any cached sprites, sets renderable flag to false, and nulls references to the Stage, filters,
|
||||
* bounds and mask.
|
||||
* Removes any cached sprites, sets renderable flag to false, and nulls filters, bounds and mask.
|
||||
*
|
||||
* Also iteratively calls `destroy` on any children.
|
||||
*
|
||||
|
@ -284,7 +274,6 @@ PIXI.DisplayObject.prototype = {
|
|||
|
||||
this.hitArea = null;
|
||||
this.parent = null;
|
||||
this.stage = null;
|
||||
this.worldTransform = null;
|
||||
this.filterArea = null;
|
||||
this.renderable = false;
|
||||
|
@ -313,7 +302,7 @@ PIXI.DisplayObject.prototype = {
|
|||
* the new, updated, worldTransform property, along with the parent transform used.
|
||||
*
|
||||
* @method PIXI.DisplayObject#updateTransform
|
||||
* @param {PIXI.DisplayObject} [parent] - Optional parent to calculate this DisplayObjects transform from.
|
||||
* @param {PIXI.DisplayObjectContainer} [parent] - Optional parent to calculate this DisplayObjects transform from.
|
||||
* @return {PIXI.DisplayObject} - A reference to this DisplayObject.
|
||||
*/
|
||||
updateTransform: function (parent) {
|
||||
|
@ -411,21 +400,6 @@ PIXI.DisplayObject.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the root Stage object that this DisplayObject is connected to.
|
||||
*
|
||||
* @method PIXI.DisplayObject#setStageReference
|
||||
* @param {Phaser.Stage} stage - The stage that the object will have as its current stage reference
|
||||
* @return {PIXI.DisplayObject} - A reference to this DisplayObject.
|
||||
*/
|
||||
setStageReference: function (stage)
|
||||
{
|
||||
this.stage = stage;
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* To be overridden by classes that require it.
|
||||
*
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
* @extends DisplayObject
|
||||
* @constructor
|
||||
*/
|
||||
PIXI.DisplayObjectContainer = function()
|
||||
{
|
||||
PIXI.DisplayObjectContainer = function () {
|
||||
|
||||
PIXI.DisplayObject.call(this);
|
||||
|
||||
/**
|
||||
|
@ -36,69 +36,9 @@ PIXI.DisplayObjectContainer = function()
|
|||
|
||||
};
|
||||
|
||||
// constructor
|
||||
PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype );
|
||||
PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer;
|
||||
|
||||
/**
|
||||
* The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property width
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', {
|
||||
|
||||
get: function() {
|
||||
return this.scale.x * this.getLocalBounds().width;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
var width = this.getLocalBounds().width;
|
||||
|
||||
if (width !== 0)
|
||||
{
|
||||
this.scale.x = value / width;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scale.x = 1;
|
||||
}
|
||||
|
||||
this._width = value;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The height of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property height
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', {
|
||||
|
||||
get: function() {
|
||||
return this.scale.y * this.getLocalBounds().height;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
var height = this.getLocalBounds().height;
|
||||
|
||||
if (height !== 0)
|
||||
{
|
||||
this.scale.y = value / height;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scale.y = 1;
|
||||
}
|
||||
|
||||
this._height = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Adds a child to the container.
|
||||
*
|
||||
|
@ -106,9 +46,10 @@ Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', {
|
|||
* @param child {DisplayObject} The DisplayObject to add to the container
|
||||
* @return {DisplayObject} The child that was added.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.addChild = function(child)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.addChild = function (child) {
|
||||
|
||||
return this.addChildAt(child, this.children.length);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -119,11 +60,11 @@ PIXI.DisplayObjectContainer.prototype.addChild = function(child)
|
|||
* @param index {Number} The index to place the child in
|
||||
* @return {DisplayObject} The child that was added.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
|
||||
{
|
||||
if(index >= 0 && index <= this.children.length)
|
||||
PIXI.DisplayObjectContainer.prototype.addChildAt = function (child, index) {
|
||||
|
||||
if (index >= 0 && index <= this.children.length)
|
||||
{
|
||||
if(child.parent)
|
||||
if (child.parent)
|
||||
{
|
||||
child.parent.removeChild(child);
|
||||
}
|
||||
|
@ -132,14 +73,13 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
|
|||
|
||||
this.children.splice(index, 0, child);
|
||||
|
||||
if(this.stage)child.setStageReference(this.stage);
|
||||
|
||||
return child;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Error(child + 'addChildAt: The index '+ index +' supplied is out of bounds ' + this.children.length);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -149,16 +89,18 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
|
|||
* @param child {DisplayObject}
|
||||
* @param child2 {DisplayObject}
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2)
|
||||
{
|
||||
if(child === child2) {
|
||||
PIXI.DisplayObjectContainer.prototype.swapChildren = function (child, child2) {
|
||||
|
||||
if (child === child2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var index1 = this.getChildIndex(child);
|
||||
var index2 = this.getChildIndex(child2);
|
||||
|
||||
if(index1 < 0 || index2 < 0) {
|
||||
if (index1 < 0 || index2 < 0)
|
||||
{
|
||||
throw new Error('swapChildren: Both the supplied DisplayObjects must be a child of the caller.');
|
||||
}
|
||||
|
||||
|
@ -174,14 +116,17 @@ PIXI.DisplayObjectContainer.prototype.swapChildren = function(child, child2)
|
|||
* @param child {DisplayObject} The DisplayObject instance to identify
|
||||
* @return {Number} The index position of the child display object to identify
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.getChildIndex = function(child)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.getChildIndex = function (child) {
|
||||
|
||||
var index = this.children.indexOf(child);
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
throw new Error('The supplied DisplayObject must be a child of the caller');
|
||||
}
|
||||
|
||||
return index;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -191,15 +136,18 @@ PIXI.DisplayObjectContainer.prototype.getChildIndex = function(child)
|
|||
* @param child {DisplayObject} The child DisplayObject instance for which you want to change the index number
|
||||
* @param index {Number} The resulting index number for the child display object
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.setChildIndex = function(child, index)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.setChildIndex = function (child, index) {
|
||||
|
||||
if (index < 0 || index >= this.children.length)
|
||||
{
|
||||
throw new Error('The supplied index is out of bounds');
|
||||
}
|
||||
|
||||
var currentIndex = this.getChildIndex(child);
|
||||
|
||||
this.children.splice(currentIndex, 1); //remove from old position
|
||||
this.children.splice(index, 0, child); //add at new position
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -209,12 +157,13 @@ PIXI.DisplayObjectContainer.prototype.setChildIndex = function(child, index)
|
|||
* @param index {Number} The index to get the child from
|
||||
* @return {DisplayObject} The child at the given index, if any.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.getChildAt = function(index)
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.getChildAt = function (index) {
|
||||
|
||||
if (index < 0 || index >= this.children.length)
|
||||
{
|
||||
throw new Error('getChildAt: Supplied index '+ index +' does not exist in the child list, or the supplied DisplayObject must be a child of the caller');
|
||||
}
|
||||
|
||||
return this.children[index];
|
||||
|
||||
};
|
||||
|
@ -226,12 +175,17 @@ PIXI.DisplayObjectContainer.prototype.getChildAt = function(index)
|
|||
* @param child {DisplayObject} The DisplayObject to remove
|
||||
* @return {DisplayObject} The child that was removed.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
|
||||
{
|
||||
var index = this.children.indexOf( child );
|
||||
if(index === -1)return;
|
||||
PIXI.DisplayObjectContainer.prototype.removeChild = function (child) {
|
||||
|
||||
var index = this.children.indexOf(child);
|
||||
|
||||
if (index === -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return this.removeChildAt( index );
|
||||
return this.removeChildAt(index);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -241,15 +195,19 @@ PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
|
|||
* @param index {Number} The index to get the child from
|
||||
* @return {DisplayObject} The child that was removed.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.removeChildAt = function(index)
|
||||
{
|
||||
var child = this.getChildAt( index );
|
||||
if(this.stage)
|
||||
child.removeStageReference();
|
||||
PIXI.DisplayObjectContainer.prototype.removeChildAt = function (index) {
|
||||
|
||||
var child = this.getChildAt(index);
|
||||
|
||||
if (child)
|
||||
{
|
||||
child.parent = undefined;
|
||||
|
||||
this.children.splice(index, 1);
|
||||
}
|
||||
|
||||
child.parent = undefined;
|
||||
this.children.splice( index, 1 );
|
||||
return child;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -259,21 +217,23 @@ PIXI.DisplayObjectContainer.prototype.removeChildAt = function(index)
|
|||
* @param beginIndex {Number} The beginning position. Default value is 0.
|
||||
* @param endIndex {Number} The ending position. Default value is size of the container.
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endIndex)
|
||||
{
|
||||
var begin = beginIndex || 0;
|
||||
var end = typeof endIndex === 'number' ? endIndex : this.children.length;
|
||||
var range = end - begin;
|
||||
PIXI.DisplayObjectContainer.prototype.removeChildren = function (beginIndex, endIndex) {
|
||||
|
||||
if (range > 0 && range <= end)
|
||||
if (beginIndex === undefined) { beginIndex = 0; }
|
||||
if (endIndex === undefined) { endIndex = this.children.length; }
|
||||
|
||||
var range = endIndex - beginIndex;
|
||||
|
||||
if (range > 0 && range <= endIndex)
|
||||
{
|
||||
var removed = this.children.splice(begin, range);
|
||||
for (var i = 0; i < removed.length; i++) {
|
||||
|
||||
for (var i = 0; i < removed.length; i++)
|
||||
{
|
||||
var child = removed[i];
|
||||
if(this.stage)
|
||||
child.removeStageReference();
|
||||
child.parent = undefined;
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
else if (range === 0 && this.children.length === 0)
|
||||
|
@ -284,6 +244,7 @@ PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endI
|
|||
{
|
||||
throw new Error( 'removeChildren: Range Error, numeric values are outside the acceptable range' );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -292,8 +253,8 @@ PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endI
|
|||
* @method updateTransform
|
||||
* @private
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.updateTransform = function()
|
||||
{
|
||||
PIXI.DisplayObjectContainer.prototype.updateTransform = function () {
|
||||
|
||||
if (!this.visible)
|
||||
{
|
||||
return;
|
||||
|
@ -310,25 +271,50 @@ PIXI.DisplayObjectContainer.prototype.updateTransform = function()
|
|||
{
|
||||
this.children[i].updateTransform();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// performance increase to avoid using call.. (10x faster)
|
||||
PIXI.DisplayObjectContainer.prototype.displayObjectContainerUpdateTransform = PIXI.DisplayObjectContainer.prototype.updateTransform;
|
||||
|
||||
/**
|
||||
* Retrieves the bounds of the displayObjectContainer as a rectangle. The bounds calculation takes all visible children into consideration.
|
||||
* Retrieves the global bounds of the displayObjectContainer as a rectangle. The bounds calculation takes all visible children into consideration.
|
||||
*
|
||||
* @method getBounds
|
||||
* @param {PIXI.DisplayObject|PIXI.Matrix} [targetCoordinateSpace] Returns a rectangle that defines the area of the display object relative to the coordinate system of the targetCoordinateSpace object.
|
||||
* @return {Rectangle} The rectangular bounding area
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.getBounds = function()
|
||||
{
|
||||
if (this.children.length === 0)
|
||||
{
|
||||
return PIXI.EmptyRectangle;
|
||||
PIXI.DisplayObjectContainer.prototype.getBounds = function (targetCoordinateSpace) {
|
||||
|
||||
var isTargetCoordinateSpaceDisplayObject = (targetCoordinateSpace && targetCoordinateSpace instanceof PIXI.DisplayObject);
|
||||
var isTargetCoordinateSpaceThisOrParent = true;
|
||||
|
||||
if (!isTargetCoordinateSpaceDisplayObject)
|
||||
{
|
||||
targetCoordinateSpace = this;
|
||||
}
|
||||
else if (targetCoordinateSpace instanceof PIXI.DisplayObjectContainer)
|
||||
{
|
||||
isTargetCoordinateSpaceThisOrParent = targetCoordinateSpace.contains(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
isTargetCoordinateSpaceThisOrParent = false;
|
||||
}
|
||||
|
||||
this.updateTransform();
|
||||
var i;
|
||||
|
||||
if (isTargetCoordinateSpaceDisplayObject)
|
||||
{
|
||||
var matrixCache = targetCoordinateSpace.worldTransform;
|
||||
|
||||
targetCoordinateSpace.worldTransform = PIXI.identityMatrix;
|
||||
|
||||
for (i = 0; i < targetCoordinateSpace.children.length; i++)
|
||||
{
|
||||
targetCoordinateSpace.children[i].updateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
var minX = Infinity;
|
||||
var minY = Infinity;
|
||||
|
@ -342,10 +328,10 @@ PIXI.DisplayObjectContainer.prototype.getBounds = function()
|
|||
|
||||
var childVisible = false;
|
||||
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
for (i = 0; i < this.children.length; i++)
|
||||
{
|
||||
var child = this.children[i];
|
||||
|
||||
|
||||
if (!child.visible)
|
||||
{
|
||||
continue;
|
||||
|
@ -354,30 +340,98 @@ PIXI.DisplayObjectContainer.prototype.getBounds = function()
|
|||
childVisible = true;
|
||||
|
||||
childBounds = this.children[i].getBounds();
|
||||
|
||||
minX = minX < childBounds.x ? minX : childBounds.x;
|
||||
minY = minY < childBounds.y ? minY : childBounds.y;
|
||||
|
||||
minX = (minX < childBounds.x) ? minX : childBounds.x;
|
||||
minY = (minY < childBounds.y) ? minY : childBounds.y;
|
||||
|
||||
childMaxX = childBounds.width + childBounds.x;
|
||||
childMaxY = childBounds.height + childBounds.y;
|
||||
|
||||
maxX = maxX > childMaxX ? maxX : childMaxX;
|
||||
maxY = maxY > childMaxY ? maxY : childMaxY;
|
||||
}
|
||||
|
||||
if (!childVisible)
|
||||
{
|
||||
return PIXI.EmptyRectangle;
|
||||
maxX = (maxX > childMaxX) ? maxX : childMaxX;
|
||||
maxY = (maxY > childMaxY) ? maxY : childMaxY;
|
||||
}
|
||||
|
||||
var bounds = this._bounds;
|
||||
|
||||
if (!childVisible)
|
||||
{
|
||||
bounds = new PIXI.Rectangle();
|
||||
|
||||
var w0 = bounds.x;
|
||||
var w1 = bounds.width + bounds.x;
|
||||
|
||||
var h0 = bounds.y;
|
||||
var h1 = bounds.height + bounds.y;
|
||||
|
||||
var worldTransform = this.worldTransform;
|
||||
|
||||
var a = worldTransform.a;
|
||||
var b = worldTransform.b;
|
||||
var c = worldTransform.c;
|
||||
var d = worldTransform.d;
|
||||
var tx = worldTransform.tx;
|
||||
var ty = worldTransform.ty;
|
||||
|
||||
var x1 = a * w1 + c * h1 + tx;
|
||||
var y1 = d * h1 + b * w1 + ty;
|
||||
|
||||
var x2 = a * w0 + c * h1 + tx;
|
||||
var y2 = d * h1 + b * w0 + ty;
|
||||
|
||||
var x3 = a * w0 + c * h0 + tx;
|
||||
var y3 = d * h0 + b * w0 + ty;
|
||||
|
||||
var x4 = a * w1 + c * h0 + tx;
|
||||
var y4 = d * h0 + b * w1 + ty;
|
||||
|
||||
maxX = x1;
|
||||
maxY = y1;
|
||||
|
||||
minX = x1;
|
||||
minY = y1;
|
||||
|
||||
minX = x2 < minX ? x2 : minX;
|
||||
minX = x3 < minX ? x3 : minX;
|
||||
minX = x4 < minX ? x4 : minX;
|
||||
|
||||
minY = y2 < minY ? y2 : minY;
|
||||
minY = y3 < minY ? y3 : minY;
|
||||
minY = y4 < minY ? y4 : minY;
|
||||
|
||||
maxX = x2 > maxX ? x2 : maxX;
|
||||
maxX = x3 > maxX ? x3 : maxX;
|
||||
maxX = x4 > maxX ? x4 : maxX;
|
||||
|
||||
maxY = y2 > maxY ? y2 : maxY;
|
||||
maxY = y3 > maxY ? y3 : maxY;
|
||||
maxY = y4 > maxY ? y4 : maxY;
|
||||
}
|
||||
|
||||
bounds.x = minX;
|
||||
bounds.y = minY;
|
||||
bounds.width = maxX - minX;
|
||||
bounds.height = maxY - minY;
|
||||
|
||||
if (isTargetCoordinateSpaceDisplayObject)
|
||||
{
|
||||
targetCoordinateSpace.worldTransform = matrixCache;
|
||||
|
||||
for (i = 0; i < targetCoordinateSpace.children.length; i++)
|
||||
{
|
||||
targetCoordinateSpace.children[i].updateTransform();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isTargetCoordinateSpaceThisOrParent)
|
||||
{
|
||||
var targetCoordinateSpaceBounds = targetCoordinateSpace.getBounds();
|
||||
|
||||
bounds.x -= targetCoordinateSpaceBounds.x;
|
||||
bounds.y -= targetCoordinateSpaceBounds.y;
|
||||
}
|
||||
|
||||
return bounds;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -386,58 +440,33 @@ PIXI.DisplayObjectContainer.prototype.getBounds = function()
|
|||
* @method getLocalBounds
|
||||
* @return {Rectangle} The rectangular bounding area
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.getLocalBounds = function()
|
||||
{
|
||||
var matrixCache = this.worldTransform;
|
||||
PIXI.DisplayObjectContainer.prototype.getLocalBounds = function () {
|
||||
|
||||
this.worldTransform = PIXI.identityMatrix;
|
||||
return this.getBounds(this.parent);
|
||||
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].updateTransform();
|
||||
}
|
||||
|
||||
var bounds = this.getBounds();
|
||||
|
||||
this.worldTransform = matrixCache;
|
||||
|
||||
for (i = 0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].updateTransform();
|
||||
}
|
||||
|
||||
return bounds;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the containers Stage reference. This is the Stage that this object, and all of its children, is connected to.
|
||||
*
|
||||
* @method setStageReference
|
||||
* @param stage {Stage} the stage that the container will have as its current stage reference
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.setStageReference = function(stage)
|
||||
{
|
||||
this.stage = stage;
|
||||
|
||||
for (var i=0; i < this.children.length; i++)
|
||||
{
|
||||
this.children[i].setStageReference(stage)
|
||||
}
|
||||
};
|
||||
* Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself.
|
||||
*
|
||||
* @method contains
|
||||
* @param {DisplayObject} child
|
||||
* @returns {boolean}
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.contains = function (child) {
|
||||
|
||||
/**
|
||||
* Removes the current stage reference from the container and all of its children.
|
||||
*
|
||||
* @method removeStageReference
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype.removeStageReference = function()
|
||||
{
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
if (!child)
|
||||
{
|
||||
this.children[i].removeStageReference();
|
||||
return false;
|
||||
}
|
||||
else if (child === this)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.contains(child.parent);
|
||||
}
|
||||
|
||||
this.stage = null;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -447,9 +476,12 @@ PIXI.DisplayObjectContainer.prototype.removeStageReference = function()
|
|||
* @param renderSession {RenderSession}
|
||||
* @private
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype._renderWebGL = function(renderSession)
|
||||
{
|
||||
if (!this.visible || this.alpha <= 0) return;
|
||||
PIXI.DisplayObjectContainer.prototype._renderWebGL = function (renderSession) {
|
||||
|
||||
if (!this.visible || this.alpha <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._cacheAsBitmap)
|
||||
{
|
||||
|
@ -496,6 +528,7 @@ PIXI.DisplayObjectContainer.prototype._renderWebGL = function(renderSession)
|
|||
this.children[i]._renderWebGL(renderSession);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -505,9 +538,12 @@ PIXI.DisplayObjectContainer.prototype._renderWebGL = function(renderSession)
|
|||
* @param renderSession {RenderSession}
|
||||
* @private
|
||||
*/
|
||||
PIXI.DisplayObjectContainer.prototype._renderCanvas = function(renderSession)
|
||||
{
|
||||
if (this.visible === false || this.alpha === 0) return;
|
||||
PIXI.DisplayObjectContainer.prototype._renderCanvas = function (renderSession) {
|
||||
|
||||
if (this.visible === false || this.alpha === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._cacheAsBitmap)
|
||||
{
|
||||
|
@ -531,3 +567,63 @@ PIXI.DisplayObjectContainer.prototype._renderCanvas = function(renderSession)
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property width
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', {
|
||||
|
||||
get: function() {
|
||||
return this.getLocalBounds().width;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
var width = this.getLocalBounds().width;
|
||||
|
||||
if (width !== 0)
|
||||
{
|
||||
this.scale.x = value / width;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scale.x = 1;
|
||||
}
|
||||
|
||||
this._width = value;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The height of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
|
||||
*
|
||||
* @property height
|
||||
* @type Number
|
||||
*/
|
||||
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', {
|
||||
|
||||
get: function() {
|
||||
return this.getLocalBounds().height;
|
||||
},
|
||||
|
||||
set: function(value) {
|
||||
|
||||
var height = this.getLocalBounds().height;
|
||||
|
||||
if (height !== 0)
|
||||
{
|
||||
this.scale.y = value / height;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scale.y = 1;
|
||||
}
|
||||
|
||||
this._height = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -9,14 +9,9 @@
|
|||
* @extends DisplayObjectContainer
|
||||
* @constructor
|
||||
* @param texture {Texture} The texture for this sprite
|
||||
*
|
||||
* A sprite can be created directly from an image like this :
|
||||
* var sprite = new PIXI.Sprite.fromImage('assets/image.png');
|
||||
* yourStage.addChild(sprite);
|
||||
* then obviously don't forget to add it to the stage you have already created
|
||||
*/
|
||||
PIXI.Sprite = function(texture)
|
||||
{
|
||||
PIXI.Sprite = function (texture) {
|
||||
|
||||
PIXI.DisplayObjectContainer.call(this);
|
||||
|
||||
/**
|
||||
|
@ -96,7 +91,8 @@ PIXI.Sprite = function(texture)
|
|||
this.blendMode = PIXI.blendModes.NORMAL;
|
||||
|
||||
/**
|
||||
* The shader that will be used to render the texture to the stage. Set to null to remove a current shader.
|
||||
* The shader that will be used to render this Sprite.
|
||||
* Set to null to remove a current shader.
|
||||
*
|
||||
* @property shader
|
||||
* @type AbstractFilter
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
var container = new PIXI.SpriteBatch();
|
||||
|
||||
stage.addChild(container);
|
||||
|
||||
for(var i = 0; i < 100; i++)
|
||||
{
|
||||
var sprite = new PIXI.Sprite.fromImage("myImage.png");
|
||||
|
|
|
@ -361,10 +361,30 @@ PIXI.Tilemap.prototype._renderWholeTilemap = function (renderSession) {
|
|||
// set the global offset (e.g. screen shake)
|
||||
gl.uniform2f(shader.uOffset, renderSession.offset.x / this.game.width * 2, -renderSession.offset.y / this.game.height * 2);
|
||||
|
||||
// set the clipping limits
|
||||
gl.uniform2f(shader.uClipOffset, this._offset.x / this.game.width * 2, this._offset.y / this.game.height * 2);
|
||||
gl.uniform2f(shader.uClipLoc, this._offset.x, this._offset.y);
|
||||
gl.uniform2f(shader.uClipLimit, this._offset.x + this._displayWidth, this.game.height - (this._offset.y + this._displayHeight));
|
||||
// Set the clipping limits
|
||||
|
||||
var clipOffsetX = this._mc.x / this.game.width * 2;
|
||||
var clipOffsetY = -this._mc.y / this.game.height * 2;
|
||||
|
||||
var clipLocX = this._mc.x;
|
||||
var clipLocY = -this._mc.y;
|
||||
|
||||
// The width, going across from the LEFT OF THE SCREEN, of the clipping limit
|
||||
var clipLimitX = this._mc.x + this._displayWidth;
|
||||
|
||||
// The height, going up from the BOTTOM OF THE SCREEN, of the clipping limit
|
||||
var clipLimitY = this.game.height - (this._mc.y + this._displayHeight);
|
||||
|
||||
// console.log('render');
|
||||
// console.log(clipOffsetX, clipOffsetY);
|
||||
// console.log(clipLocX, clipLocY);
|
||||
// console.log(clipLimitX, clipLimitY);
|
||||
// console.log(this._displayWidth, this._displayHeight);
|
||||
// debugger;
|
||||
|
||||
gl.uniform2f(shader.uClipLimit, clipLimitX, clipLimitY);
|
||||
gl.uniform2f(shader.uClipOffset, clipOffsetX, clipOffsetY);
|
||||
gl.uniform2f(shader.uClipLoc, clipLocX, clipLocY);
|
||||
|
||||
// set the offset in screen units to the center of the screen
|
||||
// and flip the GL y coordinate to be zero at the top
|
||||
|
@ -380,7 +400,7 @@ PIXI.Tilemap.prototype._renderWholeTilemap = function (renderSession) {
|
|||
gl.activeTexture(gl.TEXTURE0);
|
||||
|
||||
// check if a texture is dirty...
|
||||
if(this.texture.baseTexture._dirty[gl.id])
|
||||
if (this.texture.baseTexture._dirty[gl.id])
|
||||
{
|
||||
renderSession.renderer.updateTexture(this.texture.baseTexture);
|
||||
}
|
||||
|
|
|
@ -112,6 +112,16 @@ PIXI.Graphics = function()
|
|||
*/
|
||||
this.dirty = true;
|
||||
|
||||
/**
|
||||
* Used to detect if the bounds have been invalidated, by this Graphics being cleared or drawn to.
|
||||
* If this is set to true then the updateLocalBounds is called once in the postUpdate method.
|
||||
*
|
||||
* @property _boundsDirty
|
||||
* @type Boolean
|
||||
* @private
|
||||
*/
|
||||
this._boundsDirty = false;
|
||||
|
||||
/**
|
||||
* Used to detect if the webgl graphics object has changed. If this is set to true then the graphics object will be recalculated.
|
||||
*
|
||||
|
@ -203,7 +213,7 @@ PIXI.Graphics.prototype.lineTo = function(x, y)
|
|||
|
||||
this.currentPath.shape.points.push(x, y);
|
||||
this.dirty = true;
|
||||
this.updateLocalBounds();
|
||||
this._boundsDirty = true;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -258,7 +268,7 @@ PIXI.Graphics.prototype.quadraticCurveTo = function(cpX, cpY, toX, toY)
|
|||
}
|
||||
|
||||
this.dirty = true;
|
||||
this.updateLocalBounds();
|
||||
this._boundsDirty = true;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -317,7 +327,7 @@ PIXI.Graphics.prototype.bezierCurveTo = function(cpX, cpY, cpX2, cpY2, toX, toY)
|
|||
}
|
||||
|
||||
this.dirty = true;
|
||||
this.updateLocalBounds();
|
||||
this._boundsDirty = true;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -387,7 +397,7 @@ PIXI.Graphics.prototype.arcTo = function(x1, y1, x2, y2, radius)
|
|||
}
|
||||
|
||||
this.dirty = true;
|
||||
this.updateLocalBounds();
|
||||
this._boundsDirty = true;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -473,7 +483,7 @@ PIXI.Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, ant
|
|||
}
|
||||
|
||||
this.dirty = true;
|
||||
this.updateLocalBounds();
|
||||
this._boundsDirty = true;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
@ -632,6 +642,7 @@ PIXI.Graphics.prototype.clear = function()
|
|||
this.filling = false;
|
||||
|
||||
this.dirty = true;
|
||||
this._boundsDirty = true;
|
||||
this.clearDirty = true;
|
||||
this.graphicsData = [];
|
||||
|
||||
|
@ -1182,8 +1193,7 @@ PIXI.Graphics.prototype.drawShape = function(shape)
|
|||
}
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
this.updateLocalBounds();
|
||||
this._boundsDirty = true;
|
||||
|
||||
return data;
|
||||
|
||||
|
|
|
@ -150,12 +150,12 @@ PIXI.CanvasRenderer = function (game) {
|
|||
PIXI.CanvasRenderer.prototype.constructor = PIXI.CanvasRenderer;
|
||||
|
||||
/**
|
||||
* Renders the Stage to this canvas view
|
||||
* Renders the DisplayObjectContainer, usually the Phaser.Stage, to this canvas view.
|
||||
*
|
||||
* @method render
|
||||
* @param stage {Stage} the Stage element to be rendered
|
||||
* @param root {Phaser.Stage|PIXI.DisplayObjectContainer} The root element to be rendered.
|
||||
*/
|
||||
PIXI.CanvasRenderer.prototype.render = function (stage) {
|
||||
PIXI.CanvasRenderer.prototype.render = function (root) {
|
||||
|
||||
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
|
||||
|
@ -179,14 +179,14 @@ PIXI.CanvasRenderer.prototype.render = function (stage) {
|
|||
{
|
||||
this.context.clearRect(0, 0, this.width, this.height);
|
||||
}
|
||||
else
|
||||
else if (root._bgColor)
|
||||
{
|
||||
this.context.fillStyle = stage._bgColor.rgba;
|
||||
this.context.fillStyle = root._bgColor.rgba;
|
||||
this.context.fillRect(0, 0, this.width , this.height);
|
||||
}
|
||||
}
|
||||
|
||||
this.renderDisplayObject(stage);
|
||||
this.renderDisplayObject(root);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -2,20 +2,21 @@
|
|||
* @author Mat Groves http://matgroves.com/ @Doormat23
|
||||
*/
|
||||
|
||||
PIXI.glContexts = []; // this is where we store the webGL contexts for easy access.
|
||||
// this is where we store the webGL contexts for easy access.
|
||||
PIXI.glContexts = [];
|
||||
PIXI.instances = [];
|
||||
|
||||
/**
|
||||
* The WebGLRenderer draws the stage and all its content onto a webGL enabled canvas. This renderer
|
||||
* should be used for browsers that support webGL. This Render works by automatically managing webGLBatchs.
|
||||
* So no need for Sprite Batches or Sprite Clouds.
|
||||
* Don't forget to add the view to your DOM or you will not see anything :)
|
||||
* The WebGLRenderer draws the stage and all its content onto a WebGL enabled canvas.
|
||||
* This renderer should be used for browsers that support WebGL.
|
||||
* This renderer works by automatically managing WebGL Batches, so there is no need for
|
||||
* Sprite Batches or Sprite Clouds.
|
||||
*
|
||||
* @class WebGLRenderer
|
||||
* @constructor
|
||||
* @param game {Phaser.Game} A reference to the Phaser Game instance
|
||||
*/
|
||||
PIXI.WebGLRenderer = function(game) {
|
||||
PIXI.WebGLRenderer = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the Phaser Game instance.
|
||||
|
@ -258,38 +259,43 @@ PIXI.WebGLRenderer.prototype.setTexturePriority = function(textureNameCollection
|
|||
};
|
||||
|
||||
/**
|
||||
* Renders the stage to its webGL view
|
||||
* Renders the DisplayObjectContainer, usually the Phaser.Stage, to the WebGL enabled canvas.
|
||||
*
|
||||
* @method render
|
||||
* @param stage {Stage} the Stage element to be rendered
|
||||
* @param root {Phaser.Stage|PIXI.DisplayObjectContainer} The root element to be rendered.
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.render = function(stage)
|
||||
{
|
||||
// no point rendering if our context has been blown up!
|
||||
PIXI.WebGLRenderer.prototype.render = function (root) {
|
||||
|
||||
if (this.contextLost)
|
||||
{
|
||||
// No point rendering if the context is lost.
|
||||
return;
|
||||
}
|
||||
|
||||
var gl = this.gl;
|
||||
|
||||
// -- Does this need to be set every frame? -- //
|
||||
gl.viewport(0, 0, this.width, this.height);
|
||||
|
||||
// make sure we are bound to the main frame buffer
|
||||
// Bind the Frame Buffer
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
|
||||
// Clear it
|
||||
if (this.game.clearBeforeRender)
|
||||
{
|
||||
gl.clearColor(stage._bgColor.r, stage._bgColor.g, stage._bgColor.b, stage._bgColor.a);
|
||||
var color = this.game.stage._bgColor;
|
||||
|
||||
gl.clearColor(color.r, color.g, color.b, color.a);
|
||||
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
// Apply Camera Shake
|
||||
this.offset.x = this.game.camera._shake.x;
|
||||
this.offset.y = this.game.camera._shake.y;
|
||||
|
||||
this.renderDisplayObject(stage, this.projection);
|
||||
// Let the magic begin ...
|
||||
this.renderDisplayObject(root, this.projection);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -300,8 +306,8 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
|
|||
* @param projection {Point} The projection
|
||||
* @param buffer {Array} a standard WebGL buffer
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, projection, buffer, matrix)
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, projection, buffer, matrix) {
|
||||
|
||||
this.renderSession.blendModeManager.setBlendMode(PIXI.blendModes.NORMAL);
|
||||
|
||||
// reset the render session data..
|
||||
|
@ -327,6 +333,7 @@ PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, proje
|
|||
|
||||
// finish the sprite batch
|
||||
this.spriteBatch.end();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -336,15 +343,18 @@ PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, proje
|
|||
* @param width {Number} the new width of the webGL view
|
||||
* @param height {Number} the new height of the webGL view
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.resize = function(width, height)
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.resize = function (width, height) {
|
||||
|
||||
this.width = width * this.resolution;
|
||||
this.height = height * this.resolution;
|
||||
|
||||
this.view.width = this.width;
|
||||
this.view.height = this.height;
|
||||
|
||||
if (this.autoResize) {
|
||||
// TODO - This probably needs removing, along with the property
|
||||
// as it will conflict with the ScaleManager
|
||||
if (this.autoResize)
|
||||
{
|
||||
this.view.style.width = this.width / this.resolution + 'px';
|
||||
this.view.style.height = this.height / this.resolution + 'px';
|
||||
}
|
||||
|
@ -353,17 +363,18 @@ PIXI.WebGLRenderer.prototype.resize = function(width, height)
|
|||
|
||||
this.projection.x = this.width / 2 / this.resolution;
|
||||
this.projection.y = -this.height / 2 / this.resolution;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates and Creates a WebGL texture for the renderers context.
|
||||
* Updates and creates a WebGL texture for the renderers context.
|
||||
*
|
||||
* @method updateTexture
|
||||
* @param texture {Texture} the texture to update
|
||||
* @return {boolean} True if the texture was successfully bound, otherwise false.
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.updateTexture = function (texture) {
|
||||
|
||||
if (!texture.hasLoaded)
|
||||
{
|
||||
return false;
|
||||
|
@ -408,7 +419,6 @@ PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
|
|||
|
||||
texture._dirty[gl.id] = false;
|
||||
|
||||
// return texture._glTextures[gl.id];
|
||||
return true;
|
||||
|
||||
};
|
||||
|
@ -418,8 +428,8 @@ PIXI.WebGLRenderer.prototype.updateTexture = function(texture)
|
|||
*
|
||||
* @method destroy
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.destroy = function()
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.destroy = function () {
|
||||
|
||||
PIXI.glContexts[this.glContextId] = null;
|
||||
|
||||
this.projection = null;
|
||||
|
@ -443,6 +453,7 @@ PIXI.WebGLRenderer.prototype.destroy = function()
|
|||
PIXI.instances[this.glContextId] = null;
|
||||
|
||||
PIXI.WebGLRenderer.glContextId--;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -450,8 +461,8 @@ PIXI.WebGLRenderer.prototype.destroy = function()
|
|||
*
|
||||
* @method mapBlendModes
|
||||
*/
|
||||
PIXI.WebGLRenderer.prototype.mapBlendModes = function()
|
||||
{
|
||||
PIXI.WebGLRenderer.prototype.mapBlendModes = function () {
|
||||
|
||||
var gl = this.gl;
|
||||
|
||||
if (!PIXI.blendModesWebGL)
|
||||
|
@ -479,6 +490,7 @@ PIXI.WebGLRenderer.prototype.mapBlendModes = function()
|
|||
|
||||
PIXI.blendModesWebGL = b;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
PIXI.WebGLRenderer.glContextId = 0;
|
||||
|
|
|
@ -575,8 +575,6 @@ Phaser.Tilemap.prototype = {
|
|||
*/
|
||||
createLayer: function (layer, width, height, group) {
|
||||
|
||||
if (width === undefined) { width = this.game.width; }
|
||||
if (height === undefined) { height = this.game.height; }
|
||||
if (group === undefined) { group = this.game.world; }
|
||||
|
||||
var index = layer;
|
||||
|
@ -592,6 +590,26 @@ Phaser.Tilemap.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
// Sort out the display dimensions, so they never render too much, or too little.
|
||||
|
||||
if (width === undefined || width <= 0)
|
||||
{
|
||||
width = Math.min(this.game.width, this.layers[index].widthInPixels);
|
||||
}
|
||||
else if (width > this.game.width)
|
||||
{
|
||||
width = this.game.width;
|
||||
}
|
||||
|
||||
if (height === undefined || height <= 0)
|
||||
{
|
||||
height = Math.min(this.game.height, this.layers[index].heightInPixels);
|
||||
}
|
||||
else if (height > this.game.height)
|
||||
{
|
||||
height = this.game.height;
|
||||
}
|
||||
|
||||
if (this.enableDebug)
|
||||
{
|
||||
console.group('Tilemap.createLayer');
|
||||
|
@ -605,47 +623,39 @@ Phaser.Tilemap.prototype = {
|
|||
if (this.game.renderType === Phaser.WEBGL)
|
||||
{
|
||||
rootLayer = group.add(new Phaser.TilemapLayerGL(this.game, this, index, width, height, this.tilesets[0]));
|
||||
|
||||
// Create child layers for multiple tilesets in a layer
|
||||
// It is currently assumed that each base layer will use tileset[0] (so 'i' starts at 1 in the for loop)
|
||||
// (a 'base' layer is any layer except the so-called 'internal' layers created here)
|
||||
|
||||
var fromLayer = this.layers[index];
|
||||
var childLayer;
|
||||
|
||||
for (var i = 1; i < this.tilesets.length; i++)
|
||||
{
|
||||
if (this.checkChildLayer(this.tilesets[i], fromLayer))
|
||||
{
|
||||
childLayer = group.add(new Phaser.TilemapLayerGL(this.game, this, index, width, height, this.tilesets[i]));
|
||||
|
||||
rootLayer.linkedLayers.push(childLayer);
|
||||
|
||||
if (this.enableDebug)
|
||||
{
|
||||
console.log('Linked child created for tileset:', this.tilesets[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rootLayer = group.add(new Phaser.TilemapLayer(this.game, this, index, width, height));
|
||||
}
|
||||
|
||||
// Create child layers for multiple tilesets in a layer
|
||||
// It is currently assumed that each base layer will use tileset[0] (so 'i' starts at 1 in the for loop)
|
||||
// (a 'base' layer is any layer except the so-called 'internal' layers created here)
|
||||
|
||||
var fromLayer = this.layers[index];
|
||||
var childLayer;
|
||||
|
||||
for (var i = 1; i < this.tilesets.length; i++)
|
||||
{
|
||||
if (this.checkChildLayer(this.tilesets[i], fromLayer))
|
||||
{
|
||||
if (this.game.renderType === Phaser.WEBGL)
|
||||
{
|
||||
childLayer = group.add(new Phaser.TilemapLayerGL(this.game, this, index, width, height, this.tilesets[i]));
|
||||
}
|
||||
else
|
||||
{
|
||||
childLayer = group.add(new Phaser.TilemapLayer(this.game, this, index, width, height, this.tilesets[i]));
|
||||
}
|
||||
|
||||
rootLayer.linkedLayers.push(childLayer);
|
||||
|
||||
if (this.enableDebug)
|
||||
{
|
||||
console.log('Linked child created for tileset:', this.tilesets[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.enableDebug)
|
||||
{
|
||||
console.groupEnd();
|
||||
}
|
||||
|
||||
|
||||
return rootLayer;
|
||||
|
||||
},
|
||||
|
@ -731,7 +741,6 @@ Phaser.Tilemap.prototype = {
|
|||
|
||||
for (var x = 0; x < width; x++)
|
||||
{
|
||||
// row.push(null);
|
||||
row.push(new Phaser.Tile(layer, -1, x, y, tileWidth, tileHeight));
|
||||
}
|
||||
|
||||
|
@ -758,14 +767,16 @@ Phaser.Tilemap.prototype = {
|
|||
}
|
||||
|
||||
var output;
|
||||
if ( this.game.renderType === Phaser.WEBGL )
|
||||
|
||||
if (this.game.renderType === Phaser.WEBGL)
|
||||
{
|
||||
output = new Phaser.TilemapLayerGL(this.game, this, this.layers.length - 1, w, h);
|
||||
output = new Phaser.TilemapLayerGL(this.game, this, this.layers.length - 1, w, h, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
output = new Phaser.TilemapLayer(this.game, this, this.layers.length - 1, w, h);
|
||||
}
|
||||
|
||||
output.name = name;
|
||||
|
||||
return group.add(output);
|
||||
|
@ -1311,10 +1322,14 @@ Phaser.Tilemap.prototype = {
|
|||
hasTile: function (x, y, layer) {
|
||||
|
||||
layer = this.getLayer(layer);
|
||||
if (this.layers[layer].data[y] === undefined || this.layers[layer].data[y][x] === undefined) {
|
||||
|
||||
if (this.layers[layer].data[y] === undefined || this.layers[layer].data[y][x] === undefined)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (this.layers[layer].data[y][x].index > -1);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,6 +35,15 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
|
|||
*/
|
||||
this.map = tilemap;
|
||||
|
||||
/**
|
||||
* A custom view.
|
||||
*
|
||||
* @property {Phaser.Point} view
|
||||
*/
|
||||
this.view = game.camera;
|
||||
|
||||
this._camDetatched = false;
|
||||
|
||||
/**
|
||||
* The index of this layer within the Tilemap.
|
||||
* @property {number} index
|
||||
|
@ -159,13 +168,6 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
|
|||
*/
|
||||
this.scrollFactorY = 1;
|
||||
|
||||
/**
|
||||
* If true tiles will be force rendered, even if such is not believed to be required.
|
||||
* @property {boolean} dirty
|
||||
* @protected
|
||||
*/
|
||||
this.dirty = true;
|
||||
|
||||
/**
|
||||
* When ray-casting against tiles this is the number of steps it will jump. For larger tile sizes you can increase this to improve performance.
|
||||
* @property {integer} rayStepRate
|
||||
|
@ -173,6 +175,19 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
|
|||
*/
|
||||
this.rayStepRate = 4;
|
||||
|
||||
/**
|
||||
* @property {array} _results - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this._results = [];
|
||||
|
||||
/**
|
||||
* If true tiles will be force rendered, even if such is not believed to be required.
|
||||
* @property {boolean} dirty
|
||||
* @protected
|
||||
*/
|
||||
this.dirty = true;
|
||||
|
||||
/**
|
||||
* Flag controlling if the layer tiles wrap at the edges.
|
||||
* @property {boolean} _wrap
|
||||
|
@ -221,19 +236,12 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) {
|
|||
*/
|
||||
this._scrollY = 0;
|
||||
|
||||
/**
|
||||
* Used for caching the tiles / array of tiles.
|
||||
* @property {Phaser.Tile[]} _results
|
||||
* @private
|
||||
*/
|
||||
this._results = [];
|
||||
|
||||
if (!game.device.canvasBitBltShift)
|
||||
{
|
||||
this.renderSettings.copyCanvas = Phaser.TilemapLayer.ensureSharedCopyCanvas();
|
||||
}
|
||||
|
||||
this.fixedToCamera = true;
|
||||
// this.fixedToCamera = true;
|
||||
|
||||
};
|
||||
|
||||
|
@ -263,7 +271,7 @@ Phaser.TilemapLayer.ensureSharedCopyCanvas = function () {
|
|||
|
||||
if (!this.sharedCopyCanvas)
|
||||
{
|
||||
this.sharedCopyCanvas = Phaser.Canvas.create(2, 2);
|
||||
this.sharedCopyCanvas = PIXI.CanvasPool.create(this, 2, 2);
|
||||
}
|
||||
|
||||
return this.sharedCopyCanvas;
|
||||
|
@ -281,6 +289,20 @@ Phaser.TilemapLayer.prototype.preUpdate = function() {
|
|||
|
||||
};
|
||||
|
||||
Phaser.TilemapLayer.prototype.addCamera = function () {
|
||||
|
||||
this.view = this.game.camera;
|
||||
this._camDetatched = true;
|
||||
|
||||
};
|
||||
|
||||
Phaser.TilemapLayer.prototype.removeCamera = function (x, y) {
|
||||
|
||||
this.view = new Phaser.Point(x, y);
|
||||
this._camDetatched = true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Automatically called by World.postUpdate. Handles cache updates.
|
||||
*
|
||||
|
@ -291,12 +313,12 @@ Phaser.TilemapLayer.prototype.postUpdate = function () {
|
|||
|
||||
if (this.fixedToCamera)
|
||||
{
|
||||
this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
|
||||
this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
|
||||
// this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
|
||||
// this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
|
||||
}
|
||||
|
||||
this._scrollX = this.game.camera.view.x * this.scrollFactorX / this.scale.x;
|
||||
this._scrollY = this.game.camera.view.y * this.scrollFactorY / this.scale.y;
|
||||
this.scrollX = this.view.x * this.scrollFactorX / this.scale.x;
|
||||
this.scrollY = this.view.y * this.scrollFactorY / this.scale.y;
|
||||
|
||||
};
|
||||
|
||||
|
@ -315,8 +337,8 @@ Phaser.TilemapLayer.prototype._renderCanvas = function (renderSession) {
|
|||
this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
|
||||
}
|
||||
|
||||
this._scrollX = this.game.camera.view.x * this.scrollFactorX / this.scale.x;
|
||||
this._scrollY = this.game.camera.view.y * this.scrollFactorY / this.scale.y;
|
||||
this.scrollX = this.view.x * this.scrollFactorX / this.scale.x;
|
||||
this.scrollY = this.view.y * this.scrollFactorY / this.scale.y;
|
||||
|
||||
this.render();
|
||||
|
||||
|
@ -324,30 +346,6 @@ Phaser.TilemapLayer.prototype._renderCanvas = function (renderSession) {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Automatically called by the Canvas Renderer.
|
||||
* Overrides the Sprite._renderWebGL function.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#_renderWebGL
|
||||
* @private
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._renderWebGL = function (renderSession) {
|
||||
|
||||
if (this.fixedToCamera)
|
||||
{
|
||||
this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x;
|
||||
this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y;
|
||||
}
|
||||
|
||||
this._scrollX = this.game.camera.view.x * this.scrollFactorX / this.scale.x;
|
||||
this._scrollY = this.game.camera.view.y * this.scrollFactorY / this.scale.y;
|
||||
|
||||
this.render();
|
||||
|
||||
PIXI.Sprite.prototype._renderWebGL.call(this, renderSession);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys this TilemapLayer.
|
||||
*
|
||||
|
@ -390,11 +388,6 @@ Phaser.TilemapLayer.prototype.resize = function (width, height) {
|
|||
this.texture.baseTexture.width = width;
|
||||
this.texture.baseTexture.height = height;
|
||||
|
||||
this.texture.baseTexture.dirty();
|
||||
this.texture.requiresUpdate = true;
|
||||
|
||||
this.texture._updateUvs();
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
};
|
||||
|
@ -411,247 +404,6 @@ Phaser.TilemapLayer.prototype.resizeWorld = function () {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take an x coordinate that doesn't account for scrollFactorX and 'fix' it into a scrolled local space.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#_fixX
|
||||
* @private
|
||||
* @param {number} x - x coordinate in camera space
|
||||
* @return {number} x coordinate in scrollFactor-adjusted dimensions
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._fixX = function (x) {
|
||||
|
||||
if (this.scrollFactorX === 1 || (this.scrollFactorX === 0 && this.position.x === 0))
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
// This executes if the scrollFactorX is 0 and the x position of the tilemap is off from standard.
|
||||
if (this.scrollFactorX === 0 && this.position.x !== 0)
|
||||
{
|
||||
return x - this.position.x;
|
||||
}
|
||||
|
||||
return this._scrollX + (x - (this._scrollX / this.scrollFactorX));
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it back to camera space.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#_unfixX
|
||||
* @private
|
||||
* @param {number} x - x coordinate in scrollFactor-adjusted dimensions
|
||||
* @return {number} x coordinate in camera space
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._unfixX = function (x) {
|
||||
|
||||
if (this.scrollFactorX === 1)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
return (this._scrollX / this.scrollFactorX) + (x - this._scrollX);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take a y coordinate that doesn't account for scrollFactorY and 'fix' it into a scrolled local space.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#_fixY
|
||||
* @private
|
||||
* @param {number} y - y coordinate in camera space
|
||||
* @return {number} y coordinate in scrollFactor-adjusted dimensions
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._fixY = function (y) {
|
||||
|
||||
if (this.scrollFactorY === 1 || (this.scrollFactorY === 0 && this.position.y === 0))
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
// This executes if the scrollFactorY is 0 and the y position of the tilemap is off from standard.
|
||||
if (this.scrollFactorY === 0 && this.position.y !== 0)
|
||||
{
|
||||
return y - this.position.y;
|
||||
}
|
||||
|
||||
return this._scrollY + (y - (this._scrollY / this.scrollFactorY));
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it back to camera space.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#_unfixY
|
||||
* @private
|
||||
* @param {number} y - y coordinate in scrollFactor-adjusted dimensions
|
||||
* @return {number} y coordinate in camera space
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._unfixY = function (y) {
|
||||
|
||||
if (this.scrollFactorY === 1)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
return (this._scrollY / this.scrollFactorY) + (y - this._scrollY);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel value to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getTileX
|
||||
* @public
|
||||
* @param {number} x - X position of the point in target tile (in pixels).
|
||||
* @return {integer} The X map location of the tile.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getTileX = function (x) {
|
||||
|
||||
// var tileWidth = this.tileWidth * this.scale.x;
|
||||
return Math.floor(this._fixX(x) / this._mc.tileWidth);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel value to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getTileY
|
||||
* @public
|
||||
* @param {number} y - Y position of the point in target tile (in pixels).
|
||||
* @return {integer} The Y map location of the tile.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getTileY = function (y) {
|
||||
|
||||
// var tileHeight = this.tileHeight * this.scale.y;
|
||||
return Math.floor(this._fixY(y) / this._mc.tileHeight);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel coordinate to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getTileXY
|
||||
* @public
|
||||
* @param {number} x - X position of the point in target tile (in pixels).
|
||||
* @param {number} y - Y position of the point in target tile (in pixels).
|
||||
* @param {(Phaser.Point|object)} point - The Point/object to update.
|
||||
* @return {(Phaser.Point|object)} A Point/object with its `x` and `y` properties set.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getTileXY = function (x, y, point) {
|
||||
|
||||
point.x = this.getTileX(x);
|
||||
point.y = this.getTileY(y);
|
||||
|
||||
return point;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets all tiles that intersect with the given line.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getRayCastTiles
|
||||
* @public
|
||||
* @param {Phaser.Line} line - The line used to determine which tiles to return.
|
||||
* @param {integer} [stepRate=(rayStepRate)] - How many steps through the ray will we check? Defaults to `rayStepRate`.
|
||||
* @param {boolean} [collides=false] - If true, _only_ return tiles that collide on one or more faces.
|
||||
* @param {boolean} [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
|
||||
* @return {Phaser.Tile[]} An array of Phaser.Tiles.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getRayCastTiles = function (line, stepRate, collides, interestingFace) {
|
||||
|
||||
if (!stepRate) { stepRate = this.rayStepRate; }
|
||||
if (collides === undefined) { collides = false; }
|
||||
if (interestingFace === undefined) { interestingFace = false; }
|
||||
|
||||
// First get all tiles that touch the bounds of the line
|
||||
var tiles = this.getTiles(line.x, line.y, line.width, line.height, collides, interestingFace);
|
||||
|
||||
if (tiles.length === 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// Now we only want the tiles that intersect with the points on this line
|
||||
var coords = line.coordinatesOnLine(stepRate);
|
||||
var results = [];
|
||||
|
||||
for (var i = 0; i < tiles.length; i++)
|
||||
{
|
||||
for (var t = 0; t < coords.length; t++)
|
||||
{
|
||||
var tile = tiles[i];
|
||||
var coord = coords[t];
|
||||
if (tile.containsPoint(coord[0], coord[1]))
|
||||
{
|
||||
results.push(tile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getTiles
|
||||
* @public
|
||||
* @param {number} x - X position of the top left corner (in pixels).
|
||||
* @param {number} y - Y position of the top left corner (in pixels).
|
||||
* @param {number} width - Width of the area to get (in pixels).
|
||||
* @param {number} height - Height of the area to get (in pixels).
|
||||
* @param {boolean} [collides=false] - If true, _only_ return tiles that collide on one or more faces.
|
||||
* @param {boolean} [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
|
||||
* @return {array<Phaser.Tile>} An array of Tiles.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides, interestingFace) {
|
||||
|
||||
// Should we only get tiles that have at least one of their collision flags set? (true = yes, false = no just get them all)
|
||||
if (collides === undefined) { collides = false; }
|
||||
if (interestingFace === undefined) { interestingFace = false; }
|
||||
|
||||
var fetchAll = !(collides || interestingFace);
|
||||
|
||||
// Adjust the x,y coordinates for scrollFactor
|
||||
x = this._fixX(x);
|
||||
y = this._fixY(y);
|
||||
|
||||
// Convert the pixel values into tile coordinates
|
||||
var tx = Math.floor(x / (this._mc.cw * this.scale.x));
|
||||
var ty = Math.floor(y / (this._mc.ch * this.scale.y));
|
||||
// Don't just use ceil(width/cw) to allow account for x/y diff within cell
|
||||
var tw = Math.ceil((x + width) / (this._mc.cw * this.scale.x)) - tx;
|
||||
var th = Math.ceil((y + height) / (this._mc.ch * this.scale.y)) - ty;
|
||||
|
||||
while (this._results.length)
|
||||
{
|
||||
this._results.pop();
|
||||
}
|
||||
|
||||
for (var wy = ty; wy < ty + th; wy++)
|
||||
{
|
||||
for (var wx = tx; wx < tx + tw; wx++)
|
||||
{
|
||||
var row = this.layer.data[wy];
|
||||
|
||||
if (row && row[wx])
|
||||
{
|
||||
if (fetchAll || row[wx].isInteresting(collides, interestingFace))
|
||||
{
|
||||
this._results.push(row[wx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this._results.slice();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the appropriate tileset for the index, updating the internal cache as required.
|
||||
* This should only be called if `tilesets[index]` evaluates to undefined.
|
||||
|
@ -676,7 +428,7 @@ Phaser.TilemapLayer.prototype.resolveTileset = function (tileIndex) {
|
|||
|
||||
var setIndex = this.map.tiles[tileIndex] && this.map.tiles[tileIndex][2];
|
||||
|
||||
if (setIndex != null) // number: not null or undefined
|
||||
if (setIndex !== null)
|
||||
{
|
||||
var tileset = this.map.tilesets[setIndex];
|
||||
|
||||
|
@ -791,6 +543,7 @@ Phaser.TilemapLayer.prototype.shiftCanvas = function (context, x, y) {
|
|||
var copyContext = copyCanvas.getContext('2d');
|
||||
copyContext.clearRect(0, 0, copyW, copyH);
|
||||
copyContext.drawImage(canvas, dx, dy, copyW, copyH, 0, 0, copyW, copyH);
|
||||
|
||||
// clear allows default 'source-over' semantics
|
||||
context.clearRect(sx, sy, copyW, copyH);
|
||||
context.drawImage(copyCanvas, 0, 0, copyW, copyH, sx, sy, copyW, copyH);
|
||||
|
@ -839,6 +592,7 @@ Phaser.TilemapLayer.prototype.renderRegion = function (scrollX, scrollY, left, t
|
|||
left = Math.max(0, left);
|
||||
right = Math.min(width - 1, right);
|
||||
}
|
||||
|
||||
if (top <= bottom)
|
||||
{
|
||||
top = Math.max(0, top);
|
||||
|
@ -859,21 +613,21 @@ Phaser.TilemapLayer.prototype.renderRegion = function (scrollX, scrollY, left, t
|
|||
// xmax/ymax - remaining cells to render on column/row
|
||||
var tx, ty, x, y, xmax, ymax;
|
||||
|
||||
for (y = normStartY, ymax = bottom - top, ty = baseY;
|
||||
ymax >= 0;
|
||||
y++, ymax--, ty += th)
|
||||
for (y = normStartY, ymax = bottom - top, ty = baseY; ymax >= 0; y++, ymax--, ty += th)
|
||||
{
|
||||
|
||||
if (y >= height) { y -= height; }
|
||||
if (y >= height)
|
||||
{
|
||||
y -= height;
|
||||
}
|
||||
|
||||
var row = this.layer.data[y];
|
||||
|
||||
for (x = normStartX, xmax = right - left, tx = baseX;
|
||||
xmax >= 0;
|
||||
x++, xmax--, tx += tw)
|
||||
for (x = normStartX, xmax = right - left, tx = baseX; xmax >= 0; x++, xmax--, tx += tw)
|
||||
{
|
||||
|
||||
if (x >= width) { x -= width; }
|
||||
if (x >= width)
|
||||
{
|
||||
x -= width;
|
||||
}
|
||||
|
||||
var tile = row[x];
|
||||
|
||||
|
@ -930,9 +684,7 @@ Phaser.TilemapLayer.prototype.renderRegion = function (scrollX, scrollY, left, t
|
|||
context.fillStyle = this.debugSettings.debuggedTileOverfill;
|
||||
context.fillRect(tx, ty, tw, th);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1122,8 +874,6 @@ Phaser.TilemapLayer.prototype.render = function () {
|
|||
this.renderDebug();
|
||||
}
|
||||
|
||||
this.texture.baseTexture.dirty();
|
||||
|
||||
this.dirty = false;
|
||||
|
||||
this.context.restore();
|
||||
|
@ -1169,23 +919,24 @@ Phaser.TilemapLayer.prototype.renderDebug = function () {
|
|||
|
||||
context.strokeStyle = this.debugSettings.facingEdgeStroke;
|
||||
|
||||
for (y = normStartY, ymax = bottom - top, ty = baseY;
|
||||
ymax >= 0;
|
||||
y++, ymax--, ty += th)
|
||||
for (y = normStartY, ymax = bottom - top, ty = baseY; ymax >= 0; y++, ymax--, ty += th)
|
||||
{
|
||||
|
||||
if (y >= height) { y -= height; }
|
||||
if (y >= height)
|
||||
{
|
||||
y -= height;
|
||||
}
|
||||
|
||||
var row = this.layer.data[y];
|
||||
|
||||
for (x = normStartX, xmax = right - left, tx = baseX;
|
||||
xmax >= 0;
|
||||
x++, xmax--, tx += tw)
|
||||
for (x = normStartX, xmax = right - left, tx = baseX; xmax >= 0; x++, xmax--, tx += tw)
|
||||
{
|
||||
|
||||
if (x >= width) { x -= width; }
|
||||
if (x >= width)
|
||||
{
|
||||
x -= width;
|
||||
}
|
||||
|
||||
var tile = row[x];
|
||||
|
||||
if (!tile || tile.index < 0 || !tile.collides)
|
||||
{
|
||||
continue;
|
||||
|
@ -1225,14 +976,356 @@ Phaser.TilemapLayer.prototype.renderDebug = function () {
|
|||
context.lineTo(tx + this._mc.cw, ty + this._mc.ch);
|
||||
}
|
||||
|
||||
context.closePath();
|
||||
|
||||
context.stroke();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take an x coordinate that doesn't account for scrollFactorX and 'fix' it into a scrolled local space.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#_fixX
|
||||
* @private
|
||||
* @param {number} x - x coordinate in camera space
|
||||
* @return {number} x coordinate in scrollFactor-adjusted dimensions
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._fixX = function (x) {
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (this.scrollFactorX === 1 && !this._camDetatched)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
return this._scrollX + (x - (this._scrollX / this.scrollFactorX));
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it back to camera space.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#_unfixX
|
||||
* @private
|
||||
* @param {number} x - x coordinate in scrollFactor-adjusted dimensions
|
||||
* @return {number} x coordinate in camera space
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._unfixX = function (x) {
|
||||
|
||||
if (this.scrollFactorX === 1 && !this._camDetatched)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
return (this._scrollX / this.scrollFactorX) + (x - this._scrollX);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take a y coordinate that doesn't account for scrollFactorY and 'fix' it into a scrolled local space.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#_fixY
|
||||
* @private
|
||||
* @param {number} y - y coordinate in camera space
|
||||
* @return {number} y coordinate in scrollFactor-adjusted dimensions
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._fixY = function (y) {
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (this.scrollFactorY === 1 && !this._camDetatched)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
return this._scrollY + (y - (this._scrollY / this.scrollFactorY));
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it back to camera space.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#_unfixY
|
||||
* @private
|
||||
* @param {number} y - y coordinate in scrollFactor-adjusted dimensions
|
||||
* @return {number} y coordinate in camera space
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype._unfixY = function (y) {
|
||||
|
||||
if (this.scrollFactorY === 1 && !this._camDetatched)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
return (this._scrollY / this.scrollFactorY) + (y - this._scrollY);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel value to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getTileX
|
||||
* @param {number} x - X position of the point in target tile (in pixels).
|
||||
* @return {integer} The X map location of the tile.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getTileX = function (x) {
|
||||
|
||||
return Math.floor(this._fixX(x) / this._mc.tileWidth);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel value to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getTileY
|
||||
* @param {number} y - Y position of the point in target tile (in pixels).
|
||||
* @return {integer} The Y map location of the tile.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getTileY = function (y) {
|
||||
|
||||
return Math.floor(this._fixY(y) / this._mc.tileHeight);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel coordinate to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getTileXY
|
||||
* @param {number} x - X position of the point in target tile (in pixels).
|
||||
* @param {number} y - Y position of the point in target tile (in pixels).
|
||||
* @param {(Phaser.Point|object)} point - The Point/object to update.
|
||||
* @return {(Phaser.Point|object)} A Point/object with its `x` and `y` properties set.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getTileXY = function (x, y, point) {
|
||||
|
||||
point.x = this.getTileX(x);
|
||||
point.y = this.getTileY(y);
|
||||
|
||||
return point;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets all tiles that intersect with the given line.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getRayCastTiles
|
||||
* @param {Phaser.Line} line - The line used to determine which tiles to return.
|
||||
* @param {integer} [stepRate=(rayStepRate)] - How many steps through the ray will we check? Defaults to `rayStepRate`.
|
||||
* @param {boolean} [collides=false] - If true, _only_ return tiles that collide on one or more faces.
|
||||
* @param {boolean} [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
|
||||
* @return {Phaser.Tile[]} An array of Phaser.Tiles.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getRayCastTiles = function (line, stepRate, collides, interestingFace) {
|
||||
|
||||
if (!stepRate) { stepRate = this.rayStepRate; }
|
||||
if (collides === undefined) { collides = false; }
|
||||
if (interestingFace === undefined) { interestingFace = false; }
|
||||
|
||||
// First get all tiles that touch the bounds of the line
|
||||
var tiles = this.getTiles(line.x, line.y, line.width, line.height, collides, interestingFace);
|
||||
|
||||
if (tiles.length === 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// Now we only want the tiles that intersect with the points on this line
|
||||
var coords = line.coordinatesOnLine(stepRate);
|
||||
var results = [];
|
||||
|
||||
for (var i = 0; i < tiles.length; i++)
|
||||
{
|
||||
for (var t = 0; t < coords.length; t++)
|
||||
{
|
||||
var tile = tiles[i];
|
||||
var coord = coords[t];
|
||||
|
||||
if (tile.containsPoint(coord[0], coord[1]))
|
||||
{
|
||||
results.push(tile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles.
|
||||
*
|
||||
* @method Phaser.TilemapLayer#getTiles
|
||||
* @param {number} x - X position of the top left corner (in pixels).
|
||||
* @param {number} y - Y position of the top left corner (in pixels).
|
||||
* @param {number} width - Width of the area to get (in pixels).
|
||||
* @param {number} height - Height of the area to get (in pixels).
|
||||
* @param {boolean} [collides=false] - If true, _only_ return tiles that collide on one or more faces.
|
||||
* @param {boolean} [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
|
||||
* @return {array<Phaser.Tile>} An array of Tiles.
|
||||
*/
|
||||
Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides, interestingFace) {
|
||||
|
||||
// Should we only get tiles that have at least one of their collision flags set? (true = yes, false = no just get them all)
|
||||
if (collides === undefined) { collides = false; }
|
||||
if (interestingFace === undefined) { interestingFace = false; }
|
||||
|
||||
var fetchAll = !(collides || interestingFace);
|
||||
|
||||
// Adjust the x,y coordinates for scrollFactor
|
||||
x = this._fixX(x);
|
||||
y = this._fixY(y);
|
||||
|
||||
// Convert the pixel values into tile coordinates
|
||||
var tx = Math.floor(x / (this._mc.cw * this.scale.x));
|
||||
var ty = Math.floor(y / (this._mc.ch * this.scale.y));
|
||||
|
||||
// Don't just use ceil(width/cw) to allow account for x/y diff within cell
|
||||
var tw = Math.ceil((x + width) / (this._mc.cw * this.scale.x)) - tx;
|
||||
var th = Math.ceil((y + height) / (this._mc.ch * this.scale.y)) - ty;
|
||||
|
||||
this._results.length = 0;
|
||||
|
||||
for (var wy = ty; wy < ty + th; wy++)
|
||||
{
|
||||
for (var wx = tx; wx < tx + tw; wx++)
|
||||
{
|
||||
var row = this.layer.data[wy];
|
||||
|
||||
if (row && row[wx] && (fetchAll || row[wx].isInteresting(collides, interestingFace)))
|
||||
{
|
||||
this._results.push(row[wx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this._results.slice();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The x position of this Tilemap Layer.
|
||||
*
|
||||
* @property {integer} x
|
||||
* @memberof Phaser.TilemapLayer
|
||||
* @public
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayer.prototype, "x", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.cameraOffset.x;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.cameraOffset.x = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The y position of this Tilemap Layer.
|
||||
*
|
||||
* @property {integer} y
|
||||
* @memberof Phaser.TilemapLayer
|
||||
* @public
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayer.prototype, "y", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.cameraOffset.y;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.cameraOffset.y = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The x position of this Tilemap Layer.
|
||||
*
|
||||
* @property {integer} x
|
||||
* @memberof Phaser.TilemapLayer
|
||||
* @public
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayer.prototype, "offsetX", {
|
||||
|
||||
get: function () {
|
||||
|
||||
if (this._camDetatched)
|
||||
{
|
||||
return this.cameraOffset.x - this.view.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.cameraOffset.x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* The y position of this Tilemap Layer.
|
||||
*
|
||||
* @property {integer} y
|
||||
* @memberof Phaser.TilemapLayer
|
||||
* @public
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayer.prototype, "offsetY", {
|
||||
|
||||
get: function () {
|
||||
|
||||
if (this._camDetatched)
|
||||
{
|
||||
return this.cameraOffset.y - this.view.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.cameraOffset.y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.TilemapLayer.prototype, "bottom", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.cameraOffset.y + this.layer.heightInPixels;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.TilemapLayer.prototype, "right", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.cameraOffset.x + this.layer.widthInPixels;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Flag controlling if the layer tiles wrap at the edges. Only works if the World size matches the Map size.
|
||||
|
@ -1245,12 +1338,16 @@ Phaser.TilemapLayer.prototype.renderDebug = function () {
|
|||
Object.defineProperty(Phaser.TilemapLayer.prototype, "wrap", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._wrap;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this._wrap = value;
|
||||
this.dirty = true;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1265,11 +1362,15 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "wrap", {
|
|||
Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollX", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._scrollX;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this._scrollX = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1284,11 +1385,15 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollX", {
|
|||
Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._scrollY;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this._scrollY = value;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1303,12 +1408,16 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", {
|
|||
Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionWidth", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._mc.cw;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this._mc.cw = value | 0;
|
||||
this.dirty = true;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1323,12 +1432,16 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionWidth", {
|
|||
Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionHeight", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._mc.ch;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this._mc.ch = value | 0;
|
||||
this.dirty = true;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -6,36 +6,38 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* A TilemapLayerGL is a PIXI.Tilemap that renders a specific TileLayer of a Tilemap using the PIXI WebGL renderer.
|
||||
* TilemapLayerGL is a WebGL specific version of TilemapLayer.
|
||||
* If extends PIXI.Tilemap, and renders a layer of a Tilemap, using the WebGL Tilemap shader.
|
||||
*
|
||||
* NOTE: This is a close duplicate of Phaser.TilemapLayer class, modified to support WebGL rendering, it may be possible to merge the two classes
|
||||
* although that will probably incur performance penalties due to some fundamental differences in the set-up before rendering.
|
||||
*
|
||||
* Since a PIXI.Tilemap is a PIXI.DisplayObjectContainer it can be moved around the display list, added to other groups, or display objects, etc.
|
||||
* Since a PIXI.Tilemap is a PIXI.DisplayObject it can be moved up and down the display list.
|
||||
*
|
||||
* By default TilemapLayers have fixedToCamera set to `true`. Changing this will break Camera follow and scrolling behavior.
|
||||
*
|
||||
* @class Phaser.TilemapLayerGL
|
||||
* @extends Phaser.Sprite
|
||||
* @extends PIXI.Tilemap
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Game reference to the currently running game.
|
||||
* @param {Phaser.Tilemap} tilemap - The tilemap to which this layer belongs.
|
||||
* @param {integer} index - The index of the TileLayer to render within the Tilemap.
|
||||
* @param {integer} width - Width of the renderable area of the layer (in pixels).
|
||||
* @param {integer} height - Height of the renderable area of the layer (in pixels).
|
||||
* @param {integer} width - Width of the renderable area of the layer in pixels. Cannot be null or negative.
|
||||
* @param {integer} height - Height of the renderable area of the layer in pixels. Cannot be null or negative.
|
||||
* @param {Phaser.Tileset} tileset - The Tileset this Layer uses to render with.
|
||||
*/
|
||||
Phaser.TilemapLayerGL = function (game, tilemap, index, width, height, tileset) {
|
||||
|
||||
/**
|
||||
* A reference to the Phaser.Game instance.
|
||||
*
|
||||
* @property {Phaser.Game} game
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* The rendering offset.
|
||||
* A custom view.
|
||||
*
|
||||
* @property {Phaser.Point} _offset
|
||||
* @private
|
||||
* @property {Phaser.Point} view
|
||||
*/
|
||||
this._offset = new Phaser.Point();
|
||||
this.view = null;
|
||||
|
||||
/**
|
||||
* An Array of any linked layers.
|
||||
|
@ -101,7 +103,7 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height, tileset)
|
|||
this.exists = true;
|
||||
|
||||
/**
|
||||
* Settings used for debugging and diagnostics.
|
||||
* Settings used for debugging and diagnostics. This is ignored in WebGL mode.
|
||||
*
|
||||
* @property {?string} missingImageFill - A tile is rendered as a rectangle using the following fill if a valid tileset/image cannot be found. A value of `null` prevents additional rendering for tiles without a valid tileset image. _This takes effect even when debug rendering for the layer is not enabled._
|
||||
*
|
||||
|
@ -145,13 +147,6 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height, tileset)
|
|||
*/
|
||||
this.scrollFactorY = 1;
|
||||
|
||||
/**
|
||||
* If true tiles will be force rendered, even if such is not believed to be required.
|
||||
* @property {boolean} dirty
|
||||
* @protected
|
||||
*/
|
||||
this.dirty = true;
|
||||
|
||||
/**
|
||||
* When ray-casting against tiles this is the number of steps it will jump. For larger tile sizes you can increase this to improve performance.
|
||||
* @property {integer} rayStepRate
|
||||
|
@ -159,6 +154,19 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height, tileset)
|
|||
*/
|
||||
this.rayStepRate = 4;
|
||||
|
||||
/**
|
||||
* @property {array} _results - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this._results = [];
|
||||
|
||||
/**
|
||||
* If true tiles will be force rendered, even if such is not believed to be required.
|
||||
* @property {boolean} dirty
|
||||
* @protected
|
||||
*/
|
||||
this.dirty = true;
|
||||
|
||||
/**
|
||||
* Flag controlling if the layer tiles wrap at the edges.
|
||||
* @property {boolean} _wrap
|
||||
|
@ -171,10 +179,28 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height, tileset)
|
|||
* @property {object} _mc
|
||||
* @private
|
||||
*/
|
||||
// var tileset = this.layer.tileset || this.map.tilesets[0];
|
||||
|
||||
if (tileset === undefined)
|
||||
{
|
||||
if (tilemap.layers[index] && tilemap.layers[index].tileset)
|
||||
{
|
||||
tileset = tilemap.layers[index].tileset;
|
||||
}
|
||||
else if (tilemap.tilesets[0])
|
||||
{
|
||||
tileset = tilemap.tilesets[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
tileset = null;
|
||||
}
|
||||
}
|
||||
|
||||
this._mc = {
|
||||
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
||||
// Used to bypass rendering without reliance on `dirty` and detect changes.
|
||||
scrollX: 0,
|
||||
scrollY: 0,
|
||||
|
@ -194,16 +220,13 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height, tileset)
|
|||
ch: tileset.tileHeight,
|
||||
|
||||
// the tileset for this layer
|
||||
tileset: tileset,
|
||||
|
||||
// Cached tilesets from index -> Tileset
|
||||
tilesets: []
|
||||
tileset: tileset
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The rendering mode (used by PIXI.Tilemap). Modes are: 0 - render entire screen of tiles, 1 - render entire map of tiles
|
||||
* TODO: make some constants for the rendering modes
|
||||
* The rendering mode used by PIXI.Tilemap.
|
||||
* Modes are: 0 - render entire screen of tiles, 1 - render entire map of tiles.
|
||||
* @property {number} _renderMode
|
||||
* @private
|
||||
*/
|
||||
|
@ -223,16 +246,9 @@ Phaser.TilemapLayerGL = function (game, tilemap, index, width, height, tileset)
|
|||
*/
|
||||
this._scrollY = 0;
|
||||
|
||||
/**
|
||||
* Used for caching the tiles / array of tiles.
|
||||
* @property {Phaser.Tile[]} _results
|
||||
* @private
|
||||
*/
|
||||
this._results = [];
|
||||
|
||||
var baseTexture = new PIXI.BaseTexture(tileset.image);
|
||||
|
||||
PIXI.Tilemap.call(this, new PIXI.Texture(baseTexture), width | 0, height | 0, this.map.width, this.map.height, this._mc.tileset.tileWidth, this._mc.tileset.tileHeight, this.layer);
|
||||
PIXI.Tilemap.call(this, new PIXI.Texture(baseTexture), width, height, this.map.width, this.map.height, this._mc.tileset.tileWidth, this._mc.tileset.tileHeight, this.layer);
|
||||
|
||||
Phaser.Component.Core.init.call(this, game, 0, 0, null, null);
|
||||
|
||||
|
@ -263,6 +279,18 @@ Phaser.TilemapLayerGL.prototype.preUpdate = function () {
|
|||
|
||||
};
|
||||
|
||||
Phaser.TilemapLayerGL.prototype.addCamera = function () {
|
||||
|
||||
this.view = null;
|
||||
|
||||
};
|
||||
|
||||
Phaser.TilemapLayerGL.prototype.removeCamera = function (x, y) {
|
||||
|
||||
this.view = new Phaser.Point(x, y);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Automatically called by World.postUpdate. Handles camera scrolling.
|
||||
*
|
||||
|
@ -273,11 +301,16 @@ Phaser.TilemapLayerGL.prototype.postUpdate = function () {
|
|||
|
||||
Phaser.Component.FixedToCamera.postUpdate.call(this);
|
||||
|
||||
// Stops you being able to auto-scroll the camera if it's not following a sprite
|
||||
var camera = this.game.camera;
|
||||
|
||||
this.scrollX = camera.x * this.scrollFactorX / this.scale.x;
|
||||
this.scrollY = camera.y * this.scrollFactorY / this.scale.y;
|
||||
if (this.view)
|
||||
{
|
||||
this.scrollX = this.view.x * this.scrollFactorX / this.scale.x;
|
||||
this.scrollY = this.view.y * this.scrollFactorY / this.scale.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scrollX = this.game.camera.x * this.scrollFactorX / this.scale.x;
|
||||
this.scrollY = this.game.camera.y * this.scrollFactorY / this.scale.y;
|
||||
}
|
||||
|
||||
this.render();
|
||||
|
||||
|
@ -323,247 +356,10 @@ Phaser.TilemapLayerGL.prototype.resizeWorld = function () {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take an x coordinate that doesn't account for scrollFactorX and 'fix' it into a scrolled local space.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#_fixX
|
||||
* @private
|
||||
* @param {number} x - x coordinate in camera space
|
||||
* @return {number} x coordinate in scrollFactor-adjusted dimensions
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype._fixX = function (x) {
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (this.scrollFactorX === 1)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
return this._scrollX + (x - (this._scrollX / this.scrollFactorX));
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it back to camera space.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#_unfixX
|
||||
* @private
|
||||
* @param {number} x - x coordinate in scrollFactor-adjusted dimensions
|
||||
* @return {number} x coordinate in camera space
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype._unfixX = function (x) {
|
||||
|
||||
if (this.scrollFactorX === 1)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
return (this._scrollX / this.scrollFactorX) + (x - this._scrollX);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take a y coordinate that doesn't account for scrollFactorY and 'fix' it into a scrolled local space.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#_fixY
|
||||
* @private
|
||||
* @param {number} y - y coordinate in camera space
|
||||
* @return {number} y coordinate in scrollFactor-adjusted dimensions
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype._fixY = function (y) {
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (this.scrollFactorY === 1)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
return this._scrollY + (y - (this._scrollY / this.scrollFactorY));
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it back to camera space.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#_unfixY
|
||||
* @private
|
||||
* @param {number} y - y coordinate in scrollFactor-adjusted dimensions
|
||||
* @return {number} y coordinate in camera space
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype._unfixY = function (y) {
|
||||
|
||||
if (this.scrollFactorY === 1)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
return (this._scrollY / this.scrollFactorY) + (y - this._scrollY);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel value to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getTileX
|
||||
* @public
|
||||
* @param {number} x - X position of the point in target tile (in pixels).
|
||||
* @return {integer} The X map location of the tile.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getTileX = function (x) {
|
||||
|
||||
return Math.floor(this._fixX(x) / this._mc.tileWidth);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel value to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getTileY
|
||||
* @public
|
||||
* @param {number} y - Y position of the point in target tile (in pixels).
|
||||
* @return {integer} The Y map location of the tile.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getTileY = function (y) {
|
||||
|
||||
return Math.floor(this._fixY(y) / this._mc.tileHeight);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel coordinate to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getTileXY
|
||||
* @public
|
||||
* @param {number} x - X position of the point in target tile (in pixels).
|
||||
* @param {number} y - Y position of the point in target tile (in pixels).
|
||||
* @param {(Phaser.Point|object)} point - The Point/object to update.
|
||||
* @return {(Phaser.Point|object)} A Point/object with its `x` and `y` properties set.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getTileXY = function (x, y, point) {
|
||||
|
||||
point.x = this.getTileX(x);
|
||||
point.y = this.getTileY(y);
|
||||
|
||||
return point;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets all tiles that intersect with the given line.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getRayCastTiles
|
||||
* @public
|
||||
* @param {Phaser.Line} line - The line used to determine which tiles to return.
|
||||
* @param {integer} [stepRate=(rayStepRate)] - How many steps through the ray will we check? Defaults to `rayStepRate`.
|
||||
* @param {boolean} [collides=false] - If true, _only_ return tiles that collide on one or more faces.
|
||||
* @param {boolean} [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
|
||||
* @return {Phaser.Tile[]} An array of Phaser.Tiles.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getRayCastTiles = function (line, stepRate, collides, interestingFace) {
|
||||
|
||||
if (!stepRate) { stepRate = this.rayStepRate; }
|
||||
if (collides === undefined) { collides = false; }
|
||||
if (interestingFace === undefined) { interestingFace = false; }
|
||||
|
||||
// First get all tiles that touch the bounds of the line
|
||||
var tiles = this.getTiles(line.x, line.y, line.width, line.height, collides, interestingFace);
|
||||
|
||||
if (tiles.length === 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// Now we only want the tiles that intersect with the points on this line
|
||||
var coords = line.coordinatesOnLine(stepRate);
|
||||
var results = [];
|
||||
|
||||
for (var i = 0; i < tiles.length; i++)
|
||||
{
|
||||
for (var t = 0; t < coords.length; t++)
|
||||
{
|
||||
var tile = tiles[i];
|
||||
var coord = coords[t];
|
||||
|
||||
if (tile.containsPoint(coord[0], coord[1]))
|
||||
{
|
||||
results.push(tile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getTiles
|
||||
* @public
|
||||
* @param {number} x - X position of the top left corner (in pixels).
|
||||
* @param {number} y - Y position of the top left corner (in pixels).
|
||||
* @param {number} width - Width of the area to get (in pixels).
|
||||
* @param {number} height - Height of the area to get (in pixels).
|
||||
* @param {boolean} [collides=false] - If true, _only_ return tiles that collide on one or more faces.
|
||||
* @param {boolean} [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
|
||||
* @return {array<Phaser.Tile>} An array of Tiles.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getTiles = function (x, y, width, height, collides, interestingFace) {
|
||||
|
||||
// Should we only get tiles that have at least one of their collision flags set? (true = yes, false = no just get them all)
|
||||
if (collides === undefined) { collides = false; }
|
||||
if (interestingFace === undefined) { interestingFace = false; }
|
||||
|
||||
var fetchAll = !(collides || interestingFace);
|
||||
|
||||
// Adjust the x,y coordinates for scrollFactor
|
||||
x = this._fixX(x);
|
||||
y = this._fixY(y);
|
||||
|
||||
// Convert the pixel values into tile coordinates
|
||||
var tx = Math.floor(x / (this._mc.cw * this.scale.x));
|
||||
var ty = Math.floor(y / (this._mc.ch * this.scale.y));
|
||||
|
||||
// Don't just use ceil(width/cw) to allow account for x/y diff within cell
|
||||
var tw = Math.ceil((x + width) / (this._mc.cw * this.scale.x)) - tx;
|
||||
var th = Math.ceil((y + height) / (this._mc.ch * this.scale.y)) - ty;
|
||||
|
||||
// Discard old results before storing the new ones
|
||||
this._results = [];
|
||||
|
||||
for (var wy = ty; wy < ty + th; wy++)
|
||||
{
|
||||
for (var wx = tx; wx < tx + tw; wx++)
|
||||
{
|
||||
var row = this.layer.data[wy];
|
||||
|
||||
if (row && row[wx])
|
||||
{
|
||||
if (fetchAll || row[wx].isInteresting(collides, interestingFace))
|
||||
{
|
||||
this._results.push(row[wx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this._results.slice();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The TilemapLayerGL caches tileset look-ups.
|
||||
*
|
||||
* Call this method of clear the cache if tilesets have been added or updated after the layer has been rendered.
|
||||
* Call this method to clear the cache if tilesets have been added or updated after the layer has been rendered.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#resetTilesetCache
|
||||
* @public
|
||||
|
@ -688,7 +484,7 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
|
|||
var tile = row[x];
|
||||
|
||||
// If not the Tileset this Layer uses, then skip
|
||||
if (!tile || tile.index < 0 || tile.index < this._mc.tileset.firstgid || tile.index > this._mc.lastgid)
|
||||
if (!tile || tile.index < this._mc.tileset.firstgid || tile.index > this._mc.lastgid)
|
||||
{
|
||||
// skipping some tiles, add a degenerate marker into the batch list
|
||||
this._mc.tileset.addDegenerate(this.glBatch);
|
||||
|
@ -782,21 +578,256 @@ Phaser.TilemapLayerGL.prototype.render = function () {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take an x coordinate that doesn't account for scrollFactorX and 'fix' it into a scrolled local space.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#_fixX
|
||||
* @private
|
||||
* @param {number} x - x coordinate in camera space
|
||||
* @return {number} x coordinate in scrollFactor-adjusted dimensions
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype._fixX = function (x) {
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (this.scrollFactorX === 1 && !this.view)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
return this._scrollX + (x - (this._scrollX / this.scrollFactorX));
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take an x coordinate that _does_ account for scrollFactorX and 'unfix' it back to camera space.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#_unfixX
|
||||
* @private
|
||||
* @param {number} x - x coordinate in scrollFactor-adjusted dimensions
|
||||
* @return {number} x coordinate in camera space
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype._unfixX = function (x) {
|
||||
|
||||
if (this.scrollFactorX === 1 && !this.view)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
return (this._scrollX / this.scrollFactorX) + (x - this._scrollX);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take a y coordinate that doesn't account for scrollFactorY and 'fix' it into a scrolled local space.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#_fixY
|
||||
* @private
|
||||
* @param {number} y - y coordinate in camera space
|
||||
* @return {number} y coordinate in scrollFactor-adjusted dimensions
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype._fixY = function (y) {
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (this.scrollFactorY === 1)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
return this._scrollY + (y - (this._scrollY / this.scrollFactorY));
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Take a y coordinate that _does_ account for scrollFactorY and 'unfix' it back to camera space.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#_unfixY
|
||||
* @private
|
||||
* @param {number} y - y coordinate in scrollFactor-adjusted dimensions
|
||||
* @return {number} y coordinate in camera space
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype._unfixY = function (y) {
|
||||
|
||||
if (this.scrollFactorY === 1)
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
return (this._scrollY / this.scrollFactorY) + (y - this._scrollY);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel value to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getTileX
|
||||
* @param {number} x - X position of the point in target tile (in pixels).
|
||||
* @return {integer} The X map location of the tile.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getTileX = function (x) {
|
||||
|
||||
return Math.floor(this._fixX(x) / this._mc.tileWidth);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel value to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getTileY
|
||||
* @param {number} y - Y position of the point in target tile (in pixels).
|
||||
* @return {integer} The Y map location of the tile.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getTileY = function (y) {
|
||||
|
||||
return Math.floor(this._fixY(y) / this._mc.tileHeight);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a pixel coordinate to a tile coordinate.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getTileXY
|
||||
* @param {number} x - X position of the point in target tile (in pixels).
|
||||
* @param {number} y - Y position of the point in target tile (in pixels).
|
||||
* @param {(Phaser.Point|object)} point - The Point/object to update.
|
||||
* @return {(Phaser.Point|object)} A Point/object with its `x` and `y` properties set.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getTileXY = function (x, y, point) {
|
||||
|
||||
point.x = this.getTileX(x);
|
||||
point.y = this.getTileY(y);
|
||||
|
||||
return point;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets all tiles that intersect with the given line.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getRayCastTiles
|
||||
* @param {Phaser.Line} line - The line used to determine which tiles to return.
|
||||
* @param {integer} [stepRate=(rayStepRate)] - How many steps through the ray will we check? Defaults to `rayStepRate`.
|
||||
* @param {boolean} [collides=false] - If true, _only_ return tiles that collide on one or more faces.
|
||||
* @param {boolean} [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
|
||||
* @return {Phaser.Tile[]} An array of Phaser.Tiles.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getRayCastTiles = function (line, stepRate, collides, interestingFace) {
|
||||
|
||||
if (!stepRate) { stepRate = this.rayStepRate; }
|
||||
if (collides === undefined) { collides = false; }
|
||||
if (interestingFace === undefined) { interestingFace = false; }
|
||||
|
||||
// First get all tiles that touch the bounds of the line
|
||||
var tiles = this.getTiles(line.x, line.y, line.width, line.height, collides, interestingFace);
|
||||
|
||||
if (tiles.length === 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// Now we only want the tiles that intersect with the points on this line
|
||||
var coords = line.coordinatesOnLine(stepRate);
|
||||
var results = [];
|
||||
|
||||
for (var i = 0; i < tiles.length; i++)
|
||||
{
|
||||
for (var t = 0; t < coords.length; t++)
|
||||
{
|
||||
var tile = tiles[i];
|
||||
var coord = coords[t];
|
||||
|
||||
if (tile.containsPoint(coord[0], coord[1]))
|
||||
{
|
||||
results.push(tile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles.
|
||||
*
|
||||
* @method Phaser.TilemapLayerGL#getTiles
|
||||
* @param {number} x - X position of the top left corner (in pixels).
|
||||
* @param {number} y - Y position of the top left corner (in pixels).
|
||||
* @param {number} width - Width of the area to get (in pixels).
|
||||
* @param {number} height - Height of the area to get (in pixels).
|
||||
* @param {boolean} [collides=false] - If true, _only_ return tiles that collide on one or more faces.
|
||||
* @param {boolean} [interestingFace=false] - If true, _only_ return tiles that have interesting faces.
|
||||
* @return {array<Phaser.Tile>} An array of Tiles.
|
||||
*/
|
||||
Phaser.TilemapLayerGL.prototype.getTiles = function (x, y, width, height, collides, interestingFace) {
|
||||
|
||||
// Should we only get tiles that have at least one of their collision flags set? (true = yes, false = no just get them all)
|
||||
if (collides === undefined) { collides = false; }
|
||||
if (interestingFace === undefined) { interestingFace = false; }
|
||||
|
||||
var fetchAll = !(collides || interestingFace);
|
||||
|
||||
// Adjust the x,y coordinates for scrollFactor
|
||||
x = this._fixX(x);
|
||||
y = this._fixY(y);
|
||||
|
||||
// Convert the pixel values into tile coordinates
|
||||
var tx = Math.floor(x / (this._mc.cw * this.scale.x));
|
||||
var ty = Math.floor(y / (this._mc.ch * this.scale.y));
|
||||
|
||||
// Don't just use ceil(width/cw) to allow account for x/y diff within cell
|
||||
var tw = Math.ceil((x + width) / (this._mc.cw * this.scale.x)) - tx;
|
||||
var th = Math.ceil((y + height) / (this._mc.ch * this.scale.y)) - ty;
|
||||
|
||||
this._results.length = 0;
|
||||
|
||||
for (var wy = ty; wy < ty + th; wy++)
|
||||
{
|
||||
for (var wx = tx; wx < tx + tw; wx++)
|
||||
{
|
||||
var row = this.layer.data[wy];
|
||||
|
||||
if (row && row[wx] && (fetchAll || row[wx].isInteresting(collides, interestingFace)))
|
||||
{
|
||||
this._results.push(row[wx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this._results.slice();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The x position of this Tilemap Layer.
|
||||
*
|
||||
* @property {integer} x
|
||||
* @memberof Phaser.TilemapLayerGL
|
||||
* @public
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayerGL.prototype, "x", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._offset.x;
|
||||
return this._mc.x;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this._offset.x = value;
|
||||
this._mc.x = value;
|
||||
|
||||
for (var i = 0; i < this.linkedLayers.length; i++)
|
||||
{
|
||||
this.linkedLayers[i]._offset.x = value;
|
||||
this.linkedLayers[i]._mc.x = value;
|
||||
}
|
||||
|
||||
this.dirty = true;
|
||||
|
@ -805,21 +836,28 @@ Object.defineProperty(Phaser.TilemapLayerGL.prototype, "x", {
|
|||
|
||||
});
|
||||
|
||||
/**
|
||||
* The y position of this Tilemap Layer.
|
||||
*
|
||||
* @property {integer} y
|
||||
* @memberof Phaser.TilemapLayerGL
|
||||
* @public
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayerGL.prototype, "y", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this._offset.y;
|
||||
return this._mc.y;
|
||||
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this.offset.y = value;
|
||||
this._mc.y = value;
|
||||
|
||||
for (var i = 0; i < this.linkedLayers.length; i++)
|
||||
{
|
||||
this.linkedLayers[i]._offset.y = value;
|
||||
this.linkedLayers[i]._mc.y = value;
|
||||
}
|
||||
|
||||
this.dirty = true;
|
||||
|
@ -828,6 +866,33 @@ Object.defineProperty(Phaser.TilemapLayerGL.prototype, "y", {
|
|||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.TilemapLayerGL.prototype, "bottom", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.y + this.layer.heightInPixels;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.TilemapLayerGL.prototype, "right", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.x + this.layer.widthInPixels;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The rendered width of this Tilemap Layer.
|
||||
*
|
||||
* @property {integer} width
|
||||
* @memberof Phaser.TilemapLayerGL
|
||||
* @public
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayerGL.prototype, "width", {
|
||||
|
||||
get: function () {
|
||||
|
@ -851,6 +916,13 @@ Object.defineProperty(Phaser.TilemapLayerGL.prototype, "width", {
|
|||
|
||||
});
|
||||
|
||||
/**
|
||||
* The rendered height of this Tilemap Layer.
|
||||
*
|
||||
* @property {integer} height
|
||||
* @memberof Phaser.TilemapLayerGL
|
||||
* @public
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayerGL.prototype, "height", {
|
||||
|
||||
get: function () {
|
||||
|
|
144
src/tilemap/TilemapView.js
Normal file
144
src/tilemap/TilemapView.js
Normal file
|
@ -0,0 +1,144 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2016 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @class Phaser.TilemapLayer
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Game reference to the currently running game.
|
||||
* @param {Phaser.Tilemap} tilemap - The tilemap to which this layer belongs.
|
||||
* @param {integer} index - The index of the TileLayer to render within the Tilemap.
|
||||
* @param {integer} width - Width of the renderable area of the layer (in pixels).
|
||||
* @param {integer} height - Height of the renderable area of the layer (in pixels).
|
||||
*/
|
||||
Phaser.TilemapView = function (game, tilemap, index, width, height) {
|
||||
|
||||
/**
|
||||
* A reference to the Phaser.Game instance.
|
||||
*
|
||||
* @property {Phaser.Game} game
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* A custom view.
|
||||
*
|
||||
* @property {Phaser.Point} view
|
||||
*/
|
||||
this.view = null;
|
||||
|
||||
/**
|
||||
* An Array of any linked layers.
|
||||
*
|
||||
* @property {Array} linkedLayers
|
||||
* @private
|
||||
*/
|
||||
this.linkedLayers = [];
|
||||
|
||||
/**
|
||||
* The Tilemap to which this layer is bound.
|
||||
* @property {Phaser.Tilemap} map
|
||||
* @protected
|
||||
* @readonly
|
||||
*/
|
||||
this.map = tilemap;
|
||||
|
||||
/**
|
||||
* The index of this layer within the Tilemap.
|
||||
* @property {number} index
|
||||
* @protected
|
||||
* @readonly
|
||||
*/
|
||||
this.index = index;
|
||||
|
||||
/**
|
||||
* The layer object within the Tilemap that this layer represents.
|
||||
* @property {object} layer
|
||||
* @protected
|
||||
* @readonly
|
||||
*/
|
||||
this.layer = tilemap.layers[index];
|
||||
|
||||
/**
|
||||
* The const type of this object.
|
||||
* @property {number} type
|
||||
* @readonly
|
||||
* @protected
|
||||
* @default Phaser.TILEMAPLAYER
|
||||
*/
|
||||
this.type = Phaser.TILEMAPLAYER;
|
||||
|
||||
/**
|
||||
* @property {number} physicsType - The const physics body type of this object.
|
||||
* @readonly
|
||||
*/
|
||||
this.physicsType = Phaser.TILEMAPLAYER;
|
||||
|
||||
/**
|
||||
* @property {boolean} exists - Controls if the core game loop and physics update this game object or not.
|
||||
*/
|
||||
this.exists = true;
|
||||
|
||||
/**
|
||||
* Speed at which this layer scrolls horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls half as quickly as the 'normal' camera-locked layers do).
|
||||
* @property {number} scrollFactorX
|
||||
* @public
|
||||
* @default
|
||||
*/
|
||||
this.scrollFactor = new Phaser.Point(1, 1);
|
||||
|
||||
/**
|
||||
* When ray-casting against tiles this is the number of steps it will jump. For larger tile sizes you can increase this to improve performance.
|
||||
* @property {integer} rayStepRate
|
||||
* @default
|
||||
*/
|
||||
this.rayStepRate = 4;
|
||||
|
||||
/**
|
||||
* If true tiles will be force rendered, even if such is not believed to be required.
|
||||
* @property {boolean} dirty
|
||||
* @protected
|
||||
*/
|
||||
this.dirty = true;
|
||||
|
||||
/**
|
||||
* @property {array} _results - Internal var.
|
||||
* @private
|
||||
*/
|
||||
this._results = [];
|
||||
|
||||
};
|
||||
|
||||
Phaser.TilemapView.prototype.constructor = Phaser.TilemapView;
|
||||
|
||||
Phaser.TilemapView.prototype = {
|
||||
|
||||
preUpdate: function () {
|
||||
|
||||
},
|
||||
|
||||
postUpdate: function () {
|
||||
|
||||
},
|
||||
|
||||
render: function () {
|
||||
|
||||
},
|
||||
|
||||
resize: function () {
|
||||
|
||||
},
|
||||
|
||||
resizeWorld: function () {
|
||||
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
51
typescript/phaser.d.ts
vendored
51
typescript/phaser.d.ts
vendored
|
@ -2600,6 +2600,7 @@ declare module Phaser {
|
|||
static PI2: number;
|
||||
static radToDeg(radians: number): number;
|
||||
static reverseAngle(angleRed: number): number;
|
||||
static rotateToAngle(currentAngle: number, targetAngle: number, lerp?: number): number;
|
||||
static roundAwayFromZero(value: number): number;
|
||||
static roundTo(value: number, place?: number, base?: number): number;
|
||||
static shear(n: number): number;
|
||||
|
@ -5041,6 +5042,7 @@ declare module Phaser {
|
|||
objects: any[];
|
||||
orientation: string;
|
||||
properties: any;
|
||||
rayStepRate: number;
|
||||
tileHeight: number;
|
||||
tiles: Phaser.Tile[];
|
||||
tilesets: Phaser.Tileset[];
|
||||
|
@ -5067,6 +5069,11 @@ declare module Phaser {
|
|||
getLayerIndex(name: string): number;
|
||||
getObjectIndex(name: string): number;
|
||||
getTile(x: number, y: number, layer?: any, nonNull?: boolean): Phaser.Tile;
|
||||
getRayCastTiles(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, line: Phaser.Line, stepRate?: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[];
|
||||
getTiles(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, x: number, y: number, width: number, height: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[];
|
||||
getTileX(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, x: number): number;
|
||||
getTileXY(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, x: number, y: number, point: Phaser.Point): Phaser.Point;
|
||||
getTileY(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, y: number): number;
|
||||
getTileAbove(layer: number, x: number, y: number): Phaser.Tile;
|
||||
getTileBelow(layer: number, x: number, y: number): Phaser.Tile;
|
||||
getTileLeft(layer: number, x: number, y: number): Phaser.Tile;
|
||||
|
@ -5121,7 +5128,6 @@ declare module Phaser {
|
|||
map: Phaser.Tilemap;
|
||||
name: string;
|
||||
physicsType: number;
|
||||
rayStepRate: number;
|
||||
renderSettings: { enableScrollDelta: boolean; overdrawRatio: number; copyCanvas: any; };
|
||||
scrollFactorX: number;
|
||||
scrollFactorY: number;
|
||||
|
@ -5131,11 +5137,44 @@ declare module Phaser {
|
|||
wrap: boolean;
|
||||
|
||||
destroy(): void;
|
||||
getRayCastTiles(line: Phaser.Line, stepRate?: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[];
|
||||
getTiles(x: number, y: number, width: number, height: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[];
|
||||
getTileX(x: number): number;
|
||||
getTileXY(x: number, y: number, point: Phaser.Point): Phaser.Point;
|
||||
getTileY(y: number): number;
|
||||
postUpdate(): void;
|
||||
render(): void;
|
||||
resize(width: number, height: number): void;
|
||||
resizeWorld(): void;
|
||||
resetTilesetCache(): void;
|
||||
setScale(xScale?: number, yScale?: number): void;
|
||||
updateMax(): void;
|
||||
|
||||
}
|
||||
|
||||
class TilemapLayerGL {
|
||||
|
||||
constructor(game: Phaser.Game, tilemap: Phaser.Tilemap, index: number, width?: number, height?: number, tileset?: Phaser.Tileset);
|
||||
|
||||
collisionHeight: number;
|
||||
collisionWidth: number;
|
||||
data: any;
|
||||
dirty: boolean;
|
||||
exists: boolean;
|
||||
fixedToCamera: boolean;
|
||||
game: Phaser.Game;
|
||||
index: number;
|
||||
layer: Phaser.TilemapLayer;
|
||||
map: Phaser.Tilemap;
|
||||
name: string;
|
||||
physicsType: number;
|
||||
scrollFactorX: number;
|
||||
scrollFactorY: number;
|
||||
scrollX: number;
|
||||
scrollY: number;
|
||||
type: number;
|
||||
wrap: boolean;
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
|
||||
destroy(): void;
|
||||
postUpdate(): void;
|
||||
render(): void;
|
||||
resize(width: number, height: number): void;
|
||||
|
|
18
typescript/pixi.comments.d.ts
vendored
18
typescript/pixi.comments.d.ts
vendored
|
@ -796,9 +796,7 @@ declare module PIXI {
|
|||
y: number;
|
||||
|
||||
click(e: InteractionData): void;
|
||||
displayObjectUpdateTransform(): void;
|
||||
getBounds(matrix?: Matrix): Rectangle;
|
||||
getLocalBounds(): Rectangle;
|
||||
displayObjectUpdateTransform(parent?: DisplayObjectContainer): void;
|
||||
generateTexture(resolution?: number, scaleMode?: number, renderer?: PixiRenderer | number): RenderTexture;
|
||||
mousedown(e: InteractionData): void;
|
||||
mouseout(e: InteractionData): void;
|
||||
|
@ -818,7 +816,7 @@ declare module PIXI {
|
|||
touchendoutside(e: InteractionData): void;
|
||||
touchstart(e: InteractionData): void;
|
||||
touchmove(e: InteractionData): void;
|
||||
updateTransform(parent?: PIXI.DisplayObjectContainer): void;
|
||||
updateTransform(parent?: DisplayObjectContainer): void;
|
||||
|
||||
}
|
||||
|
||||
|
@ -880,10 +878,11 @@ declare module PIXI {
|
|||
addChildAt(child: DisplayObject, index: number): DisplayObject;
|
||||
|
||||
/**
|
||||
* Retrieves the bounds of the displayObjectContainer as a rectangle. The bounds calculation takes all visible children into consideration.
|
||||
* Retrieves the global bounds of the displayObjectContainer as a rectangle. The bounds calculation takes all visible children into consideration.
|
||||
* @param targetCoordinateSpace Returns a rectangle that defines the area of the display object relative to the coordinate system of the targetCoordinateSpace object.
|
||||
* @return The rectangular bounding area
|
||||
*/
|
||||
getBounds(): Rectangle;
|
||||
getBounds(targetCoordinateSpace?: DisplayObject | Matrix): Rectangle;
|
||||
|
||||
/**
|
||||
* Returns the child at the specified index
|
||||
|
@ -952,6 +951,13 @@ declare module PIXI {
|
|||
*/
|
||||
swapChildren(child: DisplayObject, child2: DisplayObject): void;
|
||||
|
||||
/**
|
||||
* Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself.
|
||||
*
|
||||
* @param child
|
||||
*/
|
||||
contains(child: DisplayObject): boolean;
|
||||
|
||||
}
|
||||
|
||||
export class Ellipse implements HitArea {
|
||||
|
|
9
typescript/pixi.d.ts
vendored
9
typescript/pixi.d.ts
vendored
|
@ -484,9 +484,7 @@ declare module PIXI {
|
|||
y: number;
|
||||
|
||||
click(e: InteractionData): void;
|
||||
displayObjectUpdateTransform(): void;
|
||||
getBounds(matrix?: Matrix): Rectangle;
|
||||
getLocalBounds(): Rectangle;
|
||||
displayObjectUpdateTransform(parent?: DisplayObjectContainer): void;
|
||||
generateTexture(resolution?: number, scaleMode?: number, renderer?: PixiRenderer | number): RenderTexture;
|
||||
mousedown(e: InteractionData): void;
|
||||
mouseout(e: InteractionData): void;
|
||||
|
@ -506,7 +504,7 @@ declare module PIXI {
|
|||
touchendoutside(e: InteractionData): void;
|
||||
touchstart(e: InteractionData): void;
|
||||
touchmove(e: InteractionData): void;
|
||||
updateTransform(parent?: PIXI.DisplayObjectContainer): void;
|
||||
updateTransform(parent?: DisplayObjectContainer): void;
|
||||
|
||||
}
|
||||
|
||||
|
@ -521,7 +519,7 @@ declare module PIXI {
|
|||
|
||||
addChild(child: DisplayObject): DisplayObject;
|
||||
addChildAt(child: DisplayObject, index: number): DisplayObject;
|
||||
getBounds(): Rectangle;
|
||||
getBounds(targetCoordinateSpace?: DisplayObject | Matrix): Rectangle;
|
||||
getChildAt(index: number): DisplayObject;
|
||||
getChildIndex(child: DisplayObject): number;
|
||||
getLocalBounds(): Rectangle;
|
||||
|
@ -531,6 +529,7 @@ declare module PIXI {
|
|||
removeStageReference(): void;
|
||||
setChildIndex(child: DisplayObject, index: number): void;
|
||||
swapChildren(child: DisplayObject, child2: DisplayObject): void;
|
||||
contains(child: DisplayObject): boolean;
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue