Merge branch 'renderer-updates' into multitexture-gl

This commit is contained in:
Felipe Alfonso 2016-09-08 19:21:26 -03:00
commit 4ecab8a912
32 changed files with 213 additions and 172 deletions

View file

@ -315,10 +315,11 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* 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.
* Math.getShortestAngle will return the shortest angle between the two given angles. Angles are in the range -180 to 180, which is what `Sprite.angle` uses. So you can happily feed this method two sprite angles, and get the shortest angle back between them (#2494)
### Updates
* TypeScript definitions fixes and updates (thanks @calvindavis)
* TypeScript definitions fixes and updates (thanks @calvindavis @AlvaroBarua)
* Docs typo fixes (thanks @rroylance @Owumaro @boniatillo-com)
* The InputHandler.flagged property has been removed. It was never used internally, or exposed via the API, so was just overhead.
* The src/system folder has been removed and all files relocated to the src/utils folder. This doesn't change anything from an API point of view, but did change the grunt build scripts slightly.
@ -330,7 +331,11 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* 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)
* Phaser.Image now has the ScaleMinMax component.
* Animations now allow for speeds greater than 0, rather than forcing them to be greater than 1. This allows you to have animation speeds slower than 1 frame per second (thanks @jayrobin #2664)
* Weapon.fire and all related methods (fireAtXY, fireAtPointer, fireAtSprite) now all return the instance of the Phaser.Bullet that was fired, or `null` if nothing was fired. Previously it would return a boolean, but this change allows you to perform additional processing on the Bullet as required (thanks @JTronLabs #2696)
* Sound.loopFull now returns the Sound instance that was looped (thanks @hilts-vaughan #2697)
* ArcadePhysics Body.rotation now reads its initial value from sprite.angle instead of sprite.rotation. The property was immediately replaced with the correct value in Body.preUpdate regardless, but it keeps it consistent (thanks @samme #2708)
### Bug Fixes
@ -338,6 +343,10 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* 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)
* Sound.play would throw the error "Uncaught DOMException: Failed to execute 'disconnect' on 'AudioNode': the given destination is not connected." in Chrome, if you tried to play an audio marker that didn't exist, while a valid marker was already playing.
* Text bounds would incorrectly displace if the Text resolution was greater than 1 (thanks @valent-novem #2685)
* TilemapParser would calculate widthInPixels and heightInPixels were being read incorrectly from JSON data (capitalisation of properties) (thanks @hexus #2691)
* A tinted Texture in Canvas mode wouldn't be updated properly if it was also cropped, beyond the initial crop. Now a cropped texture will re-tint itself every time the crop is updated, and has changed (thanks @phoenixyjll #2688)
### Pixi Updates

View file

@ -54,7 +54,6 @@
<script src="$path/src/pixi/display/SpriteBatch.js"></script>
<script src="$path/src/pixi/utils/Utils.js"></script>
<script src="$path/src/pixi/utils/PolyK.js"></script>
<script src="$path/src/pixi/utils/EarCut.js"></script>
<script src="$path/src/pixi/utils/CanvasPool.js"></script>

View file

@ -128,6 +128,7 @@
<li class="class-depth-1"><a href="Phaser.Mouse.html">Mouse</a></li>
<li class="class-depth-1"><a href="Phaser.Keyboard.html">Keyboard</a></li>
<li class="class-depth-1"><a href="Phaser.Key.html">Key</a></li>
<li class="class-depth-1"><a href="Phaser.KeyCode.html">Key Codes</a></li>
<li class="class-depth-1"><a href="Phaser.Gamepad.html">Gamepad</a></li>
</ul>
</li>

View file

@ -240,7 +240,12 @@ The final part of the code adds the ability to jump. The up cursor is our jump k
It's time to give our little game a purpose. Let's drop a sprinkling of stars into the scene and allow the player to collect them. To achieve this we'll create a new Group called 'stars' and populate it. In our create function we add the following code (this can be seen in part8.html):
<pre class="lang:js decode:true"> stars = game.add.group();
<pre class="lang:js decode:true">
// Finally some stars to collect
stars = game.add.group();
// We will enable physics for any star that is created in this group
stars.enableBody = true;
// Here we'll create 12 of them evenly spaced apart
for (var i = 0; i &lt; 12; i++)

View file

@ -244,29 +244,33 @@ Phaser.Animation.prototype = {
},
/**
* Reverses the animation direction
*
* @method Phaser.Animation#reverse
* @return {Phaser.Animation} The animation instance.
* */
* Reverses the animation direction.
*
* @method Phaser.Animation#reverse
* @return {Phaser.Animation} The animation instance.
*/
reverse: function () {
this.reversed = !this.reversed;
return this;
},
/**
* Reverses the animation direction for the current/next animation only
* Once the onComplete event is called this method will be called again and revert
* the reversed state.
*
* @method Phaser.Animation#reverseOnce
* @return {Phaser.Animation} The animation instance.
* */
* Reverses the animation direction for the current/next animation only
* Once the onComplete event is called this method will be called again and revert
* the reversed state.
*
* @method Phaser.Animation#reverseOnce
* @return {Phaser.Animation} The animation instance.
*/
reverseOnce: function () {
this.onComplete.addOnce(this.reverse.bind(this));
this.onComplete.addOnce(this.reverse, this);
return this.reverse();
},
/**
@ -768,19 +772,19 @@ Object.defineProperty(Phaser.Animation.prototype, 'frame', {
/**
* @name Phaser.Animation#speed
* @property {number} speed - Gets or sets the current speed of the animation in frames per second. Changing this in a playing animation will take effect from the next frame. Minimum value is 1.
* @property {number} speed - Gets or sets the current speed of the animation in frames per second. Changing this in a playing animation will take effect from the next frame. Value must be greater than 0.
*/
Object.defineProperty(Phaser.Animation.prototype, 'speed', {
get: function () {
return Math.round(1000 / this.delay);
return 1000 / this.delay;
},
set: function (value) {
if (value >= 1)
if (value > 0)
{
this.delay = 1000 / value;
}

View file

@ -207,9 +207,6 @@ Phaser.AnimationManager.prototype = {
this.currentAnim = this._anims[name];
// This shouldn't be set until the Animation is played, surely?
// this.currentFrame = this.currentAnim.currentFrame;
if (this.sprite.tilingTexture)
{
this.sprite.refreshTexture = true;

View file

@ -2711,11 +2711,6 @@ Object.defineProperty(Phaser.Group.prototype, "angle", {
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
* Note that no ancestors are factored into the result, meaning that if this Group is
* nested within another Group, with heavy transforms on it, the result of this property
* is likely to be incorrect. It is safe to get and set this property if the Group is a
* top-level descendant of Phaser.World, or untransformed parents.
*
* @name Phaser.Group#centerX
* @property {number} centerX
*/
@ -2723,13 +2718,13 @@ Object.defineProperty(Phaser.Group.prototype, "centerX", {
get: function () {
return this.getBounds().centerX;
return this.getBounds(this.parent).centerX;
},
set: function (value) {
var r = this.getBounds();
var r = this.getBounds(this.parent);
var offset = this.x - r.x;
this.x = (value + offset) - r.halfWidth;
@ -2744,11 +2739,6 @@ Object.defineProperty(Phaser.Group.prototype, "centerX", {
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
* Note that no ancestors are factored into the result, meaning that if this Group is
* nested within another Group, with heavy transforms on it, the result of this property
* is likely to be incorrect. It is safe to get and set this property if the Group is a
* top-level descendant of Phaser.World, or untransformed parents.
*
* @name Phaser.Group#centerY
* @property {number} centerY
*/
@ -2756,13 +2746,13 @@ Object.defineProperty(Phaser.Group.prototype, "centerY", {
get: function () {
return this.getBounds().centerY;
return this.getBounds(this.parent).centerY;
},
set: function (value) {
var r = this.getBounds();
var r = this.getBounds(this.parent);
var offset = this.y - r.y;
this.y = (value + offset) - r.halfHeight;
@ -2777,11 +2767,6 @@ Object.defineProperty(Phaser.Group.prototype, "centerY", {
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
* Note that no ancestors are factored into the result, meaning that if this Group is
* nested within another Group, with heavy transforms on it, the result of this property
* is likely to be incorrect. It is safe to get and set this property if the Group is a
* top-level descendant of Phaser.World, or untransformed parents.
*
* @name Phaser.Group#left
* @property {number} left
*/
@ -2789,13 +2774,13 @@ Object.defineProperty(Phaser.Group.prototype, "left", {
get: function () {
return this.getBounds().left;
return this.getBounds(this.parent).left;
},
set: function (value) {
var r = this.getBounds();
var r = this.getBounds(this.parent);
var offset = this.x - r.x;
this.x = value + offset;
@ -2809,11 +2794,6 @@ Object.defineProperty(Phaser.Group.prototype, "left", {
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
* Note that no ancestors are factored into the result, meaning that if this Group is
* nested within another Group, with heavy transforms on it, the result of this property
* is likely to be incorrect. It is safe to get and set this property if the Group is a
* top-level descendant of Phaser.World, or untransformed parents.
*
* @name Phaser.Group#right
* @property {number} right
@ -2822,13 +2802,13 @@ Object.defineProperty(Phaser.Group.prototype, "right", {
get: function () {
return this.getBounds().right;
return this.getBounds(this.parent).right;
},
set: function (value) {
var r = this.getBounds();
var r = this.getBounds(this.parent);
var offset = this.x - r.x;
this.x = (value + offset) - r.width;
@ -2842,11 +2822,6 @@ Object.defineProperty(Phaser.Group.prototype, "right", {
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
* Note that no ancestors are factored into the result, meaning that if this Group is
* nested within another Group, with heavy transforms on it, the result of this property
* is likely to be incorrect. It is safe to get and set this property if the Group is a
* top-level descendant of Phaser.World, or untransformed parents.
*
* @name Phaser.Group#top
* @property {number} top
@ -2855,13 +2830,13 @@ Object.defineProperty(Phaser.Group.prototype, "top", {
get: function () {
return this.getBounds().top;
return this.getBounds(this.parent).top;
},
set: function (value) {
var r = this.getBounds();
var r = this.getBounds(this.parent);
var offset = this.y - r.y;
this.y = (value + offset);
@ -2876,11 +2851,6 @@ Object.defineProperty(Phaser.Group.prototype, "top", {
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*
* Note that no ancestors are factored into the result, meaning that if this Group is
* nested within another Group, with heavy transforms on it, the result of this property
* is likely to be incorrect. It is safe to get and set this property if the Group is a
* top-level descendant of Phaser.World, or untransformed parents.
*
* @name Phaser.Group#bottom
* @property {number} bottom
*/
@ -2888,13 +2858,13 @@ Object.defineProperty(Phaser.Group.prototype, "bottom", {
get: function () {
return this.getBounds().bottom;
return this.getBounds(this.parent).bottom;
},
set: function (value) {
var r = this.getBounds();
var r = this.getBounds(this.parent);
var offset = this.y - r.y;
this.y = (value + offset) - r.height;

View file

@ -173,7 +173,7 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
this.onOverMouseOnly = true;
/**
* Suppresse the over event if a pointer was just released and it matches the given {@link Phaser.PointerModer pointer mode bitmask}.
* Suppress the over event if a pointer was just released and it matches the given {@link Phaser.PointerModer pointer mode bitmask}.
*
* This behavior was introduced in Phaser 2.3.1; this property is a soft-revert of the change.
*

View file

@ -24,6 +24,7 @@
* @extends Phaser.Component.LoadTexture
* @extends Phaser.Component.Overlap
* @extends Phaser.Component.Reset
* @extends Phaser.Component.ScaleMinMax
* @extends Phaser.Component.Smoothed
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
@ -68,6 +69,7 @@ Phaser.Component.Core.install.call(Phaser.Image.prototype, [
'LoadTexture',
'Overlap',
'Reset',
'ScaleMinMax',
'Smoothed'
]);

View file

@ -1442,20 +1442,20 @@ Phaser.Text.prototype.updateTexture = function () {
// Align the canvas based on the bounds
if (this.style.boundsAlignH === 'right')
{
x += this.textBounds.width - this.canvas.width;
x += this.textBounds.width - this.canvas.width / this.resolution;
}
else if (this.style.boundsAlignH === 'center')
{
x += this.textBounds.halfWidth - (this.canvas.width / 2);
x += this.textBounds.halfWidth - (this.canvas.width / this.resolution / 2);
}
if (this.style.boundsAlignV === 'bottom')
{
y += this.textBounds.height - this.canvas.height;
y += this.textBounds.height - this.canvas.height / this.resolution;
}
else if (this.style.boundsAlignV === 'middle')
{
y += this.textBounds.halfHeight - (this.canvas.height / 2);
y += this.textBounds.halfHeight - (this.canvas.height / this.resolution / 2);
}
this.pivot.x = -x;

View file

@ -46,7 +46,7 @@ Phaser.Component.Crop.prototype = {
* @param {Phaser.Rectangle} rect - The Rectangle used during cropping. Pass null or no parameters to clear a previously set crop rectangle.
* @param {boolean} [copy=false] - If false `cropRect` will be stored as a reference to the given rect. If true it will copy the rect values into a local Phaser Rectangle object stored in cropRect.
*/
crop: function(rect, copy) {
crop: function (rect, copy) {
if (copy === undefined) { copy = false; }
@ -83,13 +83,18 @@ Phaser.Component.Crop.prototype = {
*
* @method
*/
updateCrop: function() {
updateCrop: function () {
if (!this.cropRect)
{
return;
}
var oldX = this.texture.crop.x;
var oldY = this.texture.crop.y;
var oldW = this.texture.crop.width;
var oldH = this.texture.crop.height;
this._crop = Phaser.Rectangle.clone(this.cropRect, this._crop);
this._crop.x += this._frame.x;
this._crop.y += this._frame.y;
@ -112,6 +117,11 @@ Phaser.Component.Crop.prototype = {
this.texture._updateUvs();
if (this.tint !== 0xffffff && (oldX !== cx || oldY !== cy || oldW !== cw || oldH !== ch))
{
this.texture.requiresReTint = true;
}
}
};

View file

@ -604,7 +604,7 @@ Phaser.Keyboard.prototype.constructor = Phaser.Keyboard;
* _Note_: Use `Phaser.KeyCode.KEY` instead of `Phaser.Keyboard.KEY` to refer to a key code;
* the latter approach is supported for compatibility.
*
* @namespace
* @class Phaser.KeyCode
*/
Phaser.KeyCode = {
/** @static */
@ -814,8 +814,10 @@ Phaser.KeyCode = {
};
// Duplicate Phaser.KeyCode values in Phaser.Keyboard for compatibility
for (var key in Phaser.KeyCode) {
if (Phaser.KeyCode.hasOwnProperty(key) && !key.match(/[a-z]/)) {
for (var key in Phaser.KeyCode)
{
if (Phaser.KeyCode.hasOwnProperty(key) && !key.match(/[a-z]/))
{
Phaser.Keyboard[key] = Phaser.KeyCode[key];
}
}

View file

@ -1165,6 +1165,10 @@ Phaser.Loader.prototype = {
/**
* Adds a Tile Map data file to the current load queue.
*
* Phaser can load data in two different formats: CSV and Tiled JSON.
*
* Tiled is a free software package, specifically for creating tilemaps, and is available from http://www.mapeditor.org
*
* You can choose to either load the data externally, by providing a URL to a json file.
* Or you can pass in a JSON object or String via the `data` parameter.
* If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache.

View file

@ -371,6 +371,36 @@ Phaser.Math = {
},
/**
* Gets the shortest angle between `angle1` and `angle2`.
* Both angles must be in the range -180 to 180, which is the same clamped
* range that `sprite.angle` uses, so you can pass in two sprite angles to
* this method, and get the shortest angle back between the two of them.
*
* The angle returned will be in the same range. If the returned angle is
* greater than 0 then it's a counter-clockwise rotation, if < 0 then it's
* a clockwise rotation.
*
* @method Phaser.Math#getShortestAngle
* @param {number} angle1 - The first angle. In the range -180 to 180.
* @param {number} angle2 - The second angle. In the range -180 to 180.
* @return {number} The shortest angle, in degrees. If greater than zero it's a counter-clockwise rotation.
*/
getShortestAngle: function (angle1, angle2) {
var difference = angle2 - angle1;
if (difference === 0)
{
return 0;
}
var times = Math.floor((difference - (-180)) / 360);
return difference - (times * 360);
},
/**
* Find the angle of a segment from (x1, y1) -> (x2, y2).
*

View file

@ -82,13 +82,13 @@ Phaser.Physics.Arcade.Body = function (sprite) {
* itself never rotates, it is always axis-aligned. However these values are passed up to the parent Sprite and updates its rotation.
* @property {number} rotation
*/
this.rotation = sprite.rotation;
this.rotation = sprite.angle;
/**
* @property {number} preRotation - The previous rotation of the physics body.
* @readonly
*/
this.preRotation = sprite.rotation;
this.preRotation = sprite.angle;
/**
* @property {number} width - The calculated width of the physics body.

View file

@ -644,16 +644,24 @@ Object.defineProperties(PIXI.DisplayObject.prototype, {
{
var item = this.parent;
do
if (!item)
{
if (!item.visible)
{
return false;
}
item = item.parent;
return this.visible;
}
else
{
do
{
if (!item.visible)
{
return false;
}
item = item.parent;
}
while (item);
}
while (item);
return true;
}

View file

@ -435,14 +435,14 @@ PIXI.DisplayObjectContainer.prototype.getBounds = function (targetCoordinateSpac
};
/**
* Retrieves the non-global local bounds of the displayObjectContainer as a rectangle. The calculation takes all visible children into consideration.
* Retrieves the non-global local bounds of the displayObjectContainer as a rectangle without any transformations. The calculation takes all visible children into consideration.
*
* @method getLocalBounds
* @return {Rectangle} The rectangular bounding area
*/
PIXI.DisplayObjectContainer.prototype.getLocalBounds = function () {
return this.getBounds(this.parent);
return this.getBounds(this);
};
@ -577,7 +577,7 @@ PIXI.DisplayObjectContainer.prototype._renderCanvas = function (renderSession) {
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', {
get: function() {
return this.getLocalBounds().width;
return this.getLocalBounds().width * this.scale.x;
},
set: function(value) {
@ -606,7 +606,7 @@ Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'width', {
Object.defineProperty(PIXI.DisplayObjectContainer.prototype, 'height', {
get: function() {
return this.getLocalBounds().height;
return this.getLocalBounds().height * this.scale.y;
},
set: function(value) {

View file

@ -180,6 +180,7 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
{
if (this.tilingTexture.needsUpdate)
{
this.tilingTexture.baseTexture.textureIndex = this.texture.baseTexture.textureIndex;
renderSession.renderer.updateTexture(this.tilingTexture.baseTexture);
this.tilingTexture.needsUpdate = false;
}
@ -196,21 +197,23 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
{
this.children[i]._renderWebGL(renderSession);
}
renderSession.spriteBatch.stop();
var restartBatch = false;
if (this._filters)
{
restartBatch = true;
renderSession.spriteBatch.stop();
renderSession.filterManager.popFilter();
}
if (this._mask)
{
if (!restartBatch)
renderSession.spriteBatch.stop();
renderSession.maskManager.popMask(this._mask, renderSession);
}
if (restartBatch)
renderSession.spriteBatch.start();
renderSession.spriteBatch.start();
};
/**

View file

@ -125,14 +125,17 @@ PIXI.PixiFastShader.prototype.init = function () {
this.uSampler = gl.getUniformLocation(program, 'uSamplerArray[0]');
var indices = [];
// HACK: we bind an empty texture to avoid WebGL warning spam.
var tempTexture = gl.createTexture();
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, tempTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, null);
for (var i = 0; i < this.MAX_TEXTURES; ++i) {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, tempTexture);
indices.push(i);
}
// NOTE:!!!
// If textures are not bound
// then we'll get a bunch of warnings like:
// "WARNING: there is no texture bound to the unit X"
// Don't be scared, everything will be alright.
gl.activeTexture(gl.TEXTURE0);
gl.uniform1iv(this.uSampler, indices);
this.projectionVector = gl.getUniformLocation(program, 'projectionVector');

View file

@ -115,14 +115,17 @@ PIXI.PixiShader.prototype.initMultitexShader = function () {
this.aTextureIndex = gl.getAttribLocation(program, 'aTextureIndex');
var indices = [];
// HACK: we bind an empty texture to avoid WebGL warning spam.
var tempTexture = gl.createTexture();
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, tempTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, null);
for (var i = 0; i < this.MAX_TEXTURES; ++i) {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, tempTexture);
indices.push(i);
}
// NOTE:!!!
// If textures are not bound
// then we'll get a bunch of warnings like:
// "WARNING: there is no texture bound to the unit X"
// Don't be scared, everything will be alright.
gl.activeTexture(gl.TEXTURE0);
gl.uniform1iv(this.uSamplerArray, indices);
// Begin worst hack eva //
@ -245,7 +248,6 @@ PIXI.PixiShader.prototype.initUniforms = function()
if (type === 'sampler2D')
{
debugger;
uniform._init = false;
if (uniform.value !== null)

View file

@ -111,14 +111,17 @@ PIXI.StripShader.prototype.init = function()
this.uSampler = gl.getUniformLocation(program, 'uSamplerArray[0]');
var indices = [];
// HACK: we bind an empty texture to avoid WebGL warning spam.
var tempTexture = gl.createTexture();
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, tempTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, null);
for (var i = 0; i < this.MAX_TEXTURES; ++i) {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, tempTexture);
indices.push(i);
}
// NOTE:!!!
// If textures are not bound
// then we'll get a bunch of warnings like:
// "WARNING: there is no texture bound to the unit X"
// Don't be scared, everything will be alright.
gl.activeTexture(gl.TEXTURE0);
gl.uniform1iv(this.uSampler, indices);
this.projectionVector = gl.getUniformLocation(program, 'projectionVector');

View file

@ -179,9 +179,8 @@ PIXI.WebGLFastSpriteBatch.prototype.end = function()
* @method render
* @param spriteBatch {WebGLSpriteBatch}
*/
PIXI.WebGLFastSpriteBatch.prototype.render = function(spriteBatch)
PIXI.WebGLFastSpriteBatch.prototype.render = function (spriteBatch)
{
debugger;
var children = spriteBatch.children;
var sprite = children[0];
@ -369,8 +368,6 @@ PIXI.WebGLFastSpriteBatch.prototype.renderSprite = function(sprite)
*/
PIXI.WebGLFastSpriteBatch.prototype.flush = function()
{
debugger;
// If the batch is length 0 then return as there is nothing to draw
if (this.currentBatchSize===0)return;

View file

@ -225,10 +225,10 @@ PIXI.WebGLSpriteBatch.prototype.render = function (sprite, matrix) {
var baseTexture = texture.baseTexture;
var gl = this.gl;
if (this.textureArray[baseTexture.textureIndex] != baseTexture) {
this.flush();
gl.activeTexture(gl.TEXTURE0 + baseTexture.textureIndex);
gl.bindTexture(gl.TEXTURE_2D, baseTexture._glTextures[gl.id]);
this.textureArray[baseTexture.textureIndex] = baseTexture;
this.flush();
}
// They provided an alternative rendering matrix, so use it
@ -362,12 +362,12 @@ PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function (sprite) {
var texture = sprite.tilingTexture;
var baseTexture = texture.baseTexture;
var gl = this.gl;
if (this.textureArray[baseTexture.textureIndex] != baseTexture) {
gl.activeTexture(gl.TEXTURE0 + baseTexture.textureIndex);
gl.bindTexture(gl.TEXTURE_2D, baseTexture._glTextures[gl.id]);
this.textureArray[baseTexture.textureIndex] = baseTexture;
var textureIndex = sprite.texture.baseTexture.textureIndex;
if (this.textureArray[textureIndex] != baseTexture) {
this.flush();
gl.activeTexture(gl.TEXTURE0 + textureIndex);
gl.bindTexture(gl.TEXTURE_2D, baseTexture._glTextures[gl.id]);
this.textureArray[textureIndex] = baseTexture;
}
// check texture..
@ -444,7 +444,6 @@ PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function (sprite) {
var d = wt.d / resolution;
var tx = wt.tx;
var ty = wt.ty;
var textureIndex = texture.baseTexture.textureIndex;
// xy
positions[i++] = a * w1 + c * h1 + tx;
positions[i++] = d * h1 + b * w1 + ty;
@ -651,9 +650,6 @@ PIXI.WebGLSpriteBatch.prototype.renderBatch = function (texture, size, startInde
// If updateTexture returns false then we cannot render it, so bail out now
return;
}
} else {
gl.activeTexture(gl.TEXTURE0 + texture.textureIndex);
gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
}
gl.drawElements(gl.TRIANGLES, size * 6, gl.UNSIGNED_SHORT, startIndex * 6 * 2);
// increment the draw count

View file

@ -699,7 +699,7 @@ Phaser.Weapon.prototype.trackPointer = function (pointer, offsetX, offsetY) {
* @param {Phaser.Sprite|Phaser.Point|Object} [from] - Optionally fires the bullet **from** the `x` and `y` properties of this object. If set this overrides `Weapon.trackedSprite` or `trackedPointer`. Pass `null` to ignore it.
* @param {number} [x] - The x coordinate, in world space, to fire the bullet **towards**. If left as `undefined` the bullet direction is based on its angle.
* @param {number} [y] - The y coordinate, in world space, to fire the bullet **towards**. If left as `undefined` the bullet direction is based on its angle.
* @return {boolean} True if a bullet was successfully fired, otherwise false.
* @return {Phaser.Bullet} The fired bullet if successful, null otherwise.
*/
Phaser.Weapon.prototype.fire = function (from, x, y) {
@ -880,7 +880,7 @@ Phaser.Weapon.prototype.fire = function (from, x, y) {
this.onFireLimit.dispatch(this, this.fireLimit);
}
}
return bullet;
};
/**
@ -889,7 +889,7 @@ Phaser.Weapon.prototype.fire = function (from, x, y) {
*
* @method Phaser.Weapon#fireAtPointer
* @param {Phaser.Pointer} [pointer] - The Pointer to fire the bullet towards.
* @return {boolean} True if a bullet was successfully fired, otherwise false.
* @return {Phaser.Bullet} The fired bullet if successful, null otherwise.
*/
Phaser.Weapon.prototype.fireAtPointer = function (pointer) {
@ -905,7 +905,7 @@ Phaser.Weapon.prototype.fireAtPointer = function (pointer) {
*
* @method Phaser.Weapon#fireAtSprite
* @param {Phaser.Sprite} [sprite] - The Sprite to fire the bullet towards.
* @return {boolean} True if a bullet was successfully fired, otherwise false.
* @return {Phaser.Bullet} The fired bullet if successful, null otherwise.
*/
Phaser.Weapon.prototype.fireAtSprite = function (sprite) {
@ -920,7 +920,7 @@ Phaser.Weapon.prototype.fireAtSprite = function (sprite) {
* @method Phaser.Weapon#fireAtXY
* @param {number} [x] - The x coordinate, in world space, to fire the bullet towards.
* @param {number} [y] - The y coordinate, in world space, to fire the bullet towards.
* @return {boolean} True if a bullet was successfully fired, otherwise false.
* @return {Phaser.Bullet} The fired bullet if successful, null otherwise.
*/
Phaser.Weapon.prototype.fireAtXY = function (x, y) {

View file

@ -498,7 +498,7 @@ Phaser.Sound.prototype = {
*/
loopFull: function (volume) {
this.play(null, 0, volume, true);
return this.play(null, 0, volume, true);
},
@ -555,6 +555,8 @@ Phaser.Sound.prototype = {
this._sound.pause();
this._sound.currentTime = 0;
}
this.isPlaying = false;
}
if (marker === '' && Object.keys(this.markers).length > 0)
@ -566,10 +568,10 @@ Phaser.Sound.prototype = {
if (marker !== '')
{
this.currentMarker = marker;
if (this.markers[marker])
{
this.currentMarker = marker;
// Playing a marker? Then we default to the marker values
this.position = this.markers[marker].start;
this.volume = this.markers[marker].volume;
@ -594,7 +596,7 @@ Phaser.Sound.prototype = {
}
else
{
// console.warn("Phaser.Sound.play: audio marker " + marker + " doesn't exist");
console.warn("Phaser.Sound.play: audio marker " + marker + " doesn't exist");
return this;
}
}

View file

@ -6,6 +6,9 @@
/**
* Creates a new Phaser.Tilemap object. The map can either be populated with data from a Tiled JSON file or from a CSV file.
*
* Tiled is a free software package specifically for creating tile maps, and is available from http://www.mapeditor.org
*
* To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key.
* When using CSV data you must provide the key and the tileWidth and tileHeight parameters.
* If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here.

View file

@ -337,8 +337,8 @@ Phaser.TilemapLayerGL.prototype.destroy = function() {
Phaser.TilemapLayerGL.prototype.resize = function (width, height) {
// These setters will automatically update any linked children
this.displayWidth = width;
this.displayHeight = height;
this.width = width;
this.height = height;
this.dirty = true;
@ -464,12 +464,14 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
// x/y - is cell location, normalized [0..width/height) in loop
// xmax/ymax - remaining cells to render on column/row
var tx, ty, x, y, xmax, ymax;
var tileset = this._mc.tileset;
for (y = normStartY, ymax = bottom - top, ty = baseY; ymax >= 0; y++, ymax--, ty += th)
{
if (y >= height)
{
y -= height;
// wrap around if coordinates go out of range 0..height
y %= height;
}
var row = this.layer.data[y];
@ -478,7 +480,8 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
{
if (x >= width)
{
x -= width;
// wrap around if coordinates go out of range 0..width
x %= width;
}
var tile = row[x];
@ -487,38 +490,34 @@ Phaser.TilemapLayerGL.prototype.renderRegion = function (scrollX, scrollY, left,
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);
tileset.addDegenerate(this.glBatch);
continue;
}
var index = tile.index;
this._mc.tileset.drawGl(this.glBatch, tx + offx, ty + offy, index, tile.alpha, tile.flippedVal);
tileset.drawGl(this.glBatch, tx + offx, ty + offy, index, tile.alpha, tile.flippedVal);
}
// at end of each row, add a degenerate marker into the batch drawing list
this._mc.tileset.addDegenerate(this.glBatch);
tileset.addDegenerate(this.glBatch);
}
};
/**
* Clear and render the entire canvas.
* Render the entire visible region of the map.
*
* @method Phaser.TilemapLayerGL#renderFull
* @private
*/
Phaser.TilemapLayerGL.prototype.renderFull = function () {
var scrollX = this._mc.scrollX;
var scrollY = this._mc.scrollY;
// var renderW = this.game._width;
// var renderH = this.game._height;
// displayWidth surely?
var renderW = this.game._width;
var renderH = this.game._height;
var renderW = this._displayWidth;
var renderH = this._displayHeight;
var tw = this._mc.tileWidth;
var th = this._mc.tileHeight;

View file

@ -201,8 +201,8 @@ Phaser.TilemapParser = {
format: Phaser.Tilemap.TILED_JSON,
version: json.version,
properties: json.properties,
widthInPixels: json.width * json.tileWidth,
heightInPixels: json.height * json.tileHeight
widthInPixels: json.width * json.tilewidth,
heightInPixels: json.height * json.tileheight
};
// Tile Layers

View file

@ -39,14 +39,6 @@ Phaser.Tileset = function (name, firstgid, width, height, margin, spacing, prope
*/
this.firstgid = firstgid | 0;
/**
* This is the ending index of the last tile index this Tileset can contain.
* This is populated automatically by Phaser.TilemapParser.parseTiledJSON.
* For a single tileset map it should be left as the default value.
* @property {integer} lastgid
*/
this.lastgid = Infinity;
/**
* The width of each tile (in pixels).
* @property {integer} tileWidth
@ -162,10 +154,10 @@ Phaser.Tileset.prototype = {
},
/**
* Sets the GL Batch data to draw a tile from this Tileset at the given coordinates
* using a WebGL renderer.
* Draws a tile from this Tileset at the given coordinates using a WebGL renderer.
*
* @method Phaser.Tileset#drawGl
* @public
* @param {Array} glBatch - A list of WebGL batch objects to draw later.
* @param {number} x - The x coordinate to draw to.
* @param {number} y - The y coordinate to draw to.
@ -230,16 +222,16 @@ Phaser.Tileset.prototype = {
},
/**
* Adds a marker for the WebGL batch display to insert a degenerate
* triangle (eg. at the end of each row of tiles)
* Adds a marker for the WebGl batch display to insert a degenerate triangle (eg. at the end of each row of tiles)
*
* @method Phaser.Tileset#addDegenerate
* @param {array} glBatch - The GL Batch data array.
* @public
* @param {[type]} glBatch [description]
*/
addDegenerate: function (glBatch) {
// Don't insert multiple degenerate markers in a row
if (glBatch[glBatch.length - 1])
// don't insert multiple degenerate markers in a row
if (glBatch.length > 0 && glBatch[glBatch.length - 1])
{
glBatch.push(null);
}

View file

@ -1,7 +1,6 @@
[
"src/pixi/primitives/Graphics.js",
"src/pixi/primitives/GraphicsData.js",
"src/pixi/utils/Polyk.js",
"src/pixi/utils/EarCut.js",
"src/pixi/renderers/webgl/utils/WebGLGraphics.js",
"src/pixi/renderers/canvas/CanvasGraphics.js",

View file

@ -809,7 +809,7 @@ declare module Phaser {
l: number;
color: number;
color32: number;
rgba: string;
rgba: string;
}
class Create {
@ -1401,6 +1401,7 @@ declare module Phaser {
physicsConfig?: any;
seed?: string;
state?: Phaser.State;
forceSetTimeOut: boolean;
}
@ -5650,10 +5651,10 @@ declare module Phaser {
createBullets(quantity?: number, key?: any, frame?: any, group?: Phaser.Group): Phaser.Weapon;
debug(x?: number, y?: number, debugBodies?: boolean): void;
destroy(): void;
fire(from?: any, x?: number, y?: number): boolean;
fireAtPointer(pointer: Phaser.Pointer): boolean;
fireAtSprite(sprite: Phaser.Sprite): boolean;
fireAtXY(x: number, y: number): boolean;
fire(from?: any, x?: number, y?: number): Phaser.Bullet;
fireAtPointer(pointer: Phaser.Pointer): Phaser.Bullet;
fireAtSprite(sprite: Phaser.Sprite): Phaser.Bullet;
fireAtXY(x: number, y: number): Phaser.Bullet;
forEach(callback: any, callbackContext: any): Phaser.Weapon;
killAll(): Phaser.Weapon;
pauseAll(): Phaser.Weapon;

View file

@ -901,7 +901,7 @@ declare module PIXI {
getChildIndex(child: DisplayObject): number;
/**
* Retrieves the non-global local bounds of the displayObjectContainer as a rectangle. The calculation takes all visible children into consideration.
* Retrieves the non-global local bounds of the displayObjectContainer as a rectangle without any transformations. The calculation takes all visible children into consideration.
* @return The rectangular bounding area
*/
getLocalBounds(): Rectangle;