Updated to latest version of Pixi.

This commit is contained in:
photonstorm 2014-08-28 23:11:13 +01:00
parent ffb413b741
commit cca955f1fd
28 changed files with 400 additions and 200 deletions

View file

@ -1,7 +1,7 @@
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
/** /**
* Holds all information related to an Interaction event * Holds all information related to an Interaction event
* *
@ -18,7 +18,7 @@ PIXI.InteractionData = function()
*/ */
this.global = new PIXI.Point(); this.global = new PIXI.Point();
/** /**
* The target Sprite that was interacted with * The target Sprite that was interacted with
* *
@ -41,9 +41,10 @@ PIXI.InteractionData = function()
* *
* @method getLocalPosition * @method getLocalPosition
* @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off * @param displayObject {DisplayObject} The DisplayObject that you would like the local coords off
* @param [point] {Point} A Point object in which to store the value, optional (otherwise will create a new point)
* @return {Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject * @return {Point} A point containing the coordinates of the InteractionData position relative to the DisplayObject
*/ */
PIXI.InteractionData.prototype.getLocalPosition = function(displayObject) PIXI.InteractionData.prototype.getLocalPosition = function(displayObject, point)
{ {
var worldTransform = displayObject.worldTransform; var worldTransform = displayObject.worldTransform;
var global = this.global; var global = this.global;
@ -52,10 +53,15 @@ PIXI.InteractionData.prototype.getLocalPosition = function(displayObject)
var a00 = worldTransform.a, a01 = worldTransform.b, a02 = worldTransform.tx, var a00 = worldTransform.a, a01 = worldTransform.b, a02 = worldTransform.tx,
a10 = worldTransform.c, a11 = worldTransform.d, a12 = worldTransform.ty, a10 = worldTransform.c, a11 = worldTransform.d, a12 = worldTransform.ty,
id = 1 / (a00 * a11 + a01 * -a10); id = 1 / (a00 * a11 + a01 * -a10);
point = point || new PIXI.Point();
point.x = a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id;
point.y = a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id;
// set the mouse coords... // set the mouse coords...
return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id, return point;
a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id);
}; };
// constructor // constructor
PIXI.InteractionData.prototype.constructor = PIXI.InteractionData; PIXI.InteractionData.prototype.constructor = PIXI.InteractionData;

View file

@ -381,22 +381,29 @@ PIXI.InteractionManager.prototype.onMouseDown = function(event)
//stage.__i //stage.__i
var length = this.interactiveItems.length; var length = this.interactiveItems.length;
var e = this.mouse.originalEvent;
var isRightButton = e.button === 2 || e.which === 3;
var downFunction = isRightButton ? 'rightdown' : 'mousedown';
var clickFunction = isRightButton ? 'rightclick' : 'click';
var buttonIsDown = isRightButton ? '__rightIsDown' : '__mouseIsDown';
var isDown = isRightButton ? '__isRightDown' : '__isDown';
// while // while
// hit test // hit test
for (var i = 0; i < length; i++) for (var i = 0; i < length; i++)
{ {
var item = this.interactiveItems[i]; var item = this.interactiveItems[i];
if(item.mousedown || item.click) if(item[downFunction] || item[clickFunction])
{ {
item.__mouseIsDown = true; item[buttonIsDown] = true;
item.__hit = this.hitTest(item, this.mouse); item.__hit = this.hitTest(item, this.mouse);
if(item.__hit) if(item.__hit)
{ {
//call the function! //call the function!
if(item.mousedown)item.mousedown(this.mouse); if(item[downFunction])item[downFunction](this.mouse);
item.__isDown = true; item[isDown] = true;
// just the one! // just the one!
if(!item.interactiveChildren)break; if(!item.interactiveChildren)break;
@ -412,13 +419,15 @@ PIXI.InteractionManager.prototype.onMouseDown = function(event)
* @param event {Event} The DOM event of a mouse button being moved out * @param event {Event} The DOM event of a mouse button being moved out
* @private * @private
*/ */
PIXI.InteractionManager.prototype.onMouseOut = function() PIXI.InteractionManager.prototype.onMouseOut = function(event)
{ {
if(this.dirty) if(this.dirty)
{ {
this.rebuildInteractiveGraph(); this.rebuildInteractiveGraph();
} }
this.mouse.originalEvent = event || window.event; //IE uses window.event
var length = this.interactiveItems.length; var length = this.interactiveItems.length;
this.interactionDOMElement.style.cursor = 'inherit'; this.interactionDOMElement.style.cursor = 'inherit';
@ -460,36 +469,46 @@ PIXI.InteractionManager.prototype.onMouseUp = function(event)
var length = this.interactiveItems.length; var length = this.interactiveItems.length;
var up = false; var up = false;
var e = this.mouse.originalEvent;
var isRightButton = e.button === 2 || e.which === 3;
var upFunction = isRightButton ? 'rightup' : 'mouseup';
var clickFunction = isRightButton ? 'rightclick' : 'click';
var upOutsideFunction = isRightButton ? 'rightupoutside' : 'mouseupoutside';
var isDown = isRightButton ? '__isRightDown' : '__isDown';
for (var i = 0; i < length; i++) for (var i = 0; i < length; i++)
{ {
var item = this.interactiveItems[i]; var item = this.interactiveItems[i];
item.__hit = this.hitTest(item, this.mouse); if(item[clickFunction] || item[upFunction] || item[upOutsideFunction])
if(item.__hit && !up)
{ {
//call the function! item.__hit = this.hitTest(item, this.mouse);
if(item.mouseup)
if(item.__hit && !up)
{ {
item.mouseup(this.mouse); //call the function!
if(item[upFunction])
{
item[upFunction](this.mouse);
}
if(item[isDown])
{
if(item[clickFunction])item[clickFunction](this.mouse);
}
if(!item.interactiveChildren)up = true;
} }
if(item.__isDown) else
{ {
if(item.click)item.click(this.mouse); if(item[isDown])
{
if(item[upOutsideFunction])item[upOutsideFunction](this.mouse);
}
} }
if(!item.interactiveChildren)up = true; item[isDown] = false;
} }
else
{
if(item.__isDown)
{
if(item.mouseupoutside)item.mouseupoutside(this.mouse);
}
}
item.__isDown = false;
//}
} }
}; };
@ -596,7 +615,8 @@ PIXI.InteractionManager.prototype.onTouchMove = function(event)
// update the touch position // update the touch position
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
if(navigator.isCocoonJS) { if(navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) {
//Support for CocoonJS fullscreen scale modes
touchData.global.x = touchEvent.clientX; touchData.global.x = touchEvent.clientX;
touchData.global.y = touchEvent.clientY; touchData.global.y = touchEvent.clientY;
} }
@ -640,7 +660,8 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event)
this.touchs[touchEvent.identifier] = touchData; this.touchs[touchEvent.identifier] = touchData;
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
if(navigator.isCocoonJS) { if(navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) {
//Support for CocoonJS fullscreen scale modes
touchData.global.x = touchEvent.clientX; touchData.global.x = touchEvent.clientX;
touchData.global.y = touchEvent.clientY; touchData.global.y = touchEvent.clientY;
} }
@ -695,7 +716,8 @@ PIXI.InteractionManager.prototype.onTouchEnd = function(event)
var up = false; var up = false;
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width); touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height); touchData.global.y = (touchEvent.clientY - rect.top) * (this.target.height / rect.height);
if(navigator.isCocoonJS) { if(navigator.isCocoonJS && !rect.left && !rect.top && !event.target.style.width && !event.target.style.height) {
//Support for CocoonJS fullscreen scale modes
touchData.global.x = touchEvent.clientX; touchData.global.x = touchEvent.clientX;
touchData.global.y = touchEvent.clientY; touchData.global.y = touchEvent.clientY;
} }

View file

@ -77,7 +77,7 @@ PIXI.Circle.prototype.contains = function(x, y)
*/ */
PIXI.Circle.prototype.getBounds = function() PIXI.Circle.prototype.getBounds = function()
{ {
return new PIXI.Rectangle(this.x - this.radius, this.y - this.radius, this.width, this.height); return new PIXI.Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
}; };
// constructor // constructor

View file

@ -78,6 +78,45 @@ PIXI.Matrix.prototype.toArray = function(transpose)
return array; return array;
}; };
/**
* Get a new position with the current transormation applied.
* Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
*
* @method apply
* @param pos {Point} The origin
* @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input)
* @return {Point} The new point, transformed trough this matrix
*/
PIXI.Matrix.prototype.apply = function(pos, newPos)
{
newPos = newPos || new PIXI.Point();
newPos.x = this.a * pos.x + this.b * pos.y + this.tx;
newPos.y = this.c * pos.x + this.d * pos.y + this.ty;
return newPos;
};
/**
* Get a new position with the inverse of the current transormation applied.
* Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
*
* @method apply
* @param pos {Point} The origin
* @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input)
* @return {Point} The new point, inverse-transformed trough this matrix
*/
PIXI.Matrix.prototype.applyInverse = function(pos, newPos)
{
newPos = newPos || new PIXI.Point();
var id = 1 / (this.a * this.d + this.b * -this.c);
newPos.x = this.d * id * pos.x - this.b * id * pos.y + (this.ty * this.b - this.tx * this.d) * id;
newPos.y = this.a * id * pos.y - this.c * id * pos.x + (this.tx * this.c - this.ty * this.a) * id;
return newPos;
};
PIXI.identityMatrix = new PIXI.Matrix(); PIXI.identityMatrix = new PIXI.Matrix();
PIXI.determineMatrixArrayType = function() { PIXI.determineMatrixArrayType = function() {

View file

@ -3,7 +3,7 @@
*/ */
/** /**
* The base class for all objects that are rendered on the screen. * The base class for all objects that are rendered on the screen.
* This is an abstract class and should not be used on its own rather it should be extended. * This is an abstract class and should not be used on its own rather it should be extended.
* *
* @class DisplayObject * @class DisplayObject
@ -123,7 +123,7 @@ PIXI.DisplayObject = function()
/** /**
* This is the cursor that will be used when the mouse is over this object. To enable this the element must have interaction = true and buttonMode = true * This is the cursor that will be used when the mouse is over this object. To enable this the element must have interaction = true and buttonMode = true
* *
* @property defaultCursor * @property defaultCursor
* @type String * @type String
* *
@ -203,33 +203,7 @@ PIXI.DisplayObject = function()
/* /*
* MOUSE Callbacks * MOUSE Callbacks
*/ */
/**
* A callback that is used when the users clicks on the displayObject with their mouse
* @method click
* @param interactionData {InteractionData}
*/
/**
* A callback that is used when the user clicks the mouse down over the sprite
* @method mousedown
* @param interactionData {InteractionData}
*/
/**
* A callback that is used when the user releases the mouse that was over the displayObject
* for this callback to be fired the mouse must have been pressed down over the displayObject
* @method mouseup
* @param interactionData {InteractionData}
*/
/**
* A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject
* for this callback to be fired, The touch must have started over the displayObject
* @method mouseupoutside
* @param interactionData {InteractionData}
*/
/** /**
* A callback that is used when the users mouse rolls over the displayObject * A callback that is used when the users mouse rolls over the displayObject
* @method mouseover * @method mouseover
@ -242,6 +216,59 @@ PIXI.DisplayObject = function()
* @param interactionData {InteractionData} * @param interactionData {InteractionData}
*/ */
//Left button
/**
* A callback that is used when the users clicks on the displayObject with their mouse's left button
* @method click
* @param interactionData {InteractionData}
*/
/**
* A callback that is used when the user clicks the mouse's left button down over the sprite
* @method mousedown
* @param interactionData {InteractionData}
*/
/**
* A callback that is used when the user releases the mouse's left button that was over the displayObject
* for this callback to be fired, the mouse's left button must have been pressed down over the displayObject
* @method mouseup
* @param interactionData {InteractionData}
*/
/**
* A callback that is used when the user releases the mouse's left button that was over the displayObject but is no longer over the displayObject
* for this callback to be fired, the mouse's left button must have been pressed down over the displayObject
* @method mouseupoutside
* @param interactionData {InteractionData}
*/
//Right button
/**
* A callback that is used when the users clicks on the displayObject with their mouse's right button
* @method rightclick
* @param interactionData {InteractionData}
*/
/**
* A callback that is used when the user clicks the mouse's right button down over the sprite
* @method rightdown
* @param interactionData {InteractionData}
*/
/**
* A callback that is used when the user releases the mouse's right button that was over the displayObject
* for this callback to be fired the mouse's right button must have been pressed down over the displayObject
* @method rightup
* @param interactionData {InteractionData}
*/
/**
* A callback that is used when the user releases the mouse's right button that was over the displayObject but is no longer over the displayObject
* for this callback to be fired, the mouse's right button must have been pressed down over the displayObject
* @method rightupoutside
* @param interactionData {InteractionData}
*/
/* /*
* TOUCH Callbacks * TOUCH Callbacks
@ -481,7 +508,6 @@ PIXI.DisplayObject.prototype.getLocalBounds = function()
return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle(); return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle();
}; };
/** /**
* Sets the object's stage reference, the stage this object is connected to * Sets the object's stage reference, the stage this object is connected to
* *
@ -509,10 +535,41 @@ PIXI.DisplayObject.prototype.updateCache = function()
this._generateCachedSprite(); this._generateCachedSprite();
}; };
/**
* Calculates the global position of the display object
*
* @method toGlobal
* @param position {Point} The world origin to calculate from
* @return {Point} A point object representing the position of this object
*/
PIXI.DisplayObject.prototype.toGlobal = function(pos)
{
this.updateTransform();
return this.worldTransform.apply(pos);
};
/**
* Calculates the local position of the display object relative to another point
*
* @method toGlobal
* @param position {Point} The world origin to calculate from
* @param [from] {DisplayObject} The DisplayObject to calculate the global position from
* @return {Point} A point object representing the position of this object
*/
PIXI.DisplayObject.prototype.toLocal = function(pos, from)
{
if (from)
{
pos = from.toGlobal(pos);
}
this.updateTransform();
return this.worldTransform.applyInverse(pos);
};
PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession) PIXI.DisplayObject.prototype._renderCachedSprite = function(renderSession)
{ {
this._cachedSprite.worldAlpha = this.worldAlpha; this._cachedSprite.worldAlpha = this.worldAlpha;
if(renderSession.gl) if(renderSession.gl)
{ {
PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession); PIXI.Sprite.prototype._renderWebGL.call(this._cachedSprite, renderSession);
@ -527,11 +584,11 @@ PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession)
{ {
this._cacheAsBitmap = false; this._cacheAsBitmap = false;
var bounds = this.getLocalBounds(); var bounds = this.getLocalBounds();
if(!this._cachedSprite) if(!this._cachedSprite)
{ {
var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer); var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer);
this._cachedSprite = new PIXI.Sprite(renderTexture); this._cachedSprite = new PIXI.Sprite(renderTexture);
this._cachedSprite.worldTransform = this.worldTransform; this._cachedSprite.worldTransform = this.worldTransform;
} }
@ -559,7 +616,7 @@ PIXI.DisplayObject.prototype._generateCachedSprite = function()//renderSession)
* Renders the object using the WebGL renderer * Renders the object using the WebGL renderer
* *
* @method _renderWebGL * @method _renderWebGL
* @param renderSession {RenderSession} * @param renderSession {RenderSession}
* @private * @private
*/ */
PIXI.DisplayObject.prototype._destroyCachedSprite = function() PIXI.DisplayObject.prototype._destroyCachedSprite = function()
@ -585,7 +642,7 @@ PIXI.DisplayObject.prototype._renderWebGL = function(renderSession)
* Renders the object using the Canvas renderer * Renders the object using the Canvas renderer
* *
* @method _renderCanvas * @method _renderCanvas
* @param renderSession {RenderSession} * @param renderSession {RenderSession}
* @private * @private
*/ */
PIXI.DisplayObject.prototype._renderCanvas = function(renderSession) PIXI.DisplayObject.prototype._renderCanvas = function(renderSession)

View file

@ -226,6 +226,10 @@ PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endI
} }
return removed; return removed;
} }
else if (range === 0 && this.children.length === 0)
{
return [];
}
else else
{ {
throw new Error( 'Range Error, numeric values are outside the acceptable range' ); throw new Error( 'Range Error, numeric values are outside the acceptable range' );

View file

@ -308,7 +308,7 @@ PIXI.Sprite.prototype._renderWebGL = function(renderSession)
PIXI.Sprite.prototype._renderCanvas = function(renderSession) PIXI.Sprite.prototype._renderCanvas = function(renderSession)
{ {
// If the sprite is not visible or the alpha is 0 then no need to render this element // If the sprite is not visible or the alpha is 0 then no need to render this element
if (this.visible === false || this.alpha === 0) return; if (this.visible === false || this.alpha === 0 || this.texture.crop.width <= 0 || this.texture.crop.height <= 0) return;
if (this.blendMode !== renderSession.currentBlendMode) if (this.blendMode !== renderSession.currentBlendMode)
{ {

View file

@ -5,6 +5,7 @@
* *
* @class Rope * @class Rope
* @constructor * @constructor
* @extends Strip
* @param texture {Texture} The texture to use * @param texture {Texture} The texture to use
* @param points {Array} * @param points {Array}
* *

View file

@ -16,6 +16,13 @@ PIXI.Strip = function(texture)
{ {
PIXI.DisplayObjectContainer.call( this ); PIXI.DisplayObjectContainer.call( this );
/**
* The texture of the strip
*
* @property texture
* @type Texture
*/
this.texture = texture; this.texture = texture;
// set up the main bits.. // set up the main bits..
@ -33,8 +40,24 @@ PIXI.Strip = function(texture)
this.indices = new PIXI.Uint16Array([0, 1, 2, 3]); this.indices = new PIXI.Uint16Array([0, 1, 2, 3]);
/**
* Whether the strip is dirty or not
*
* @property dirty
* @type Boolean
*/
this.dirty = true; this.dirty = true;
/**
* if you need a padding, not yet implemented
*
* @property padding
* @type Number
*/
this.padding = 0;
// NYI, TODO padding ?
}; };
// constructor // constructor
@ -184,7 +207,7 @@ PIXI.Strip.prototype._renderCanvas = function(renderSession)
var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4]; var x0 = verticies[index], x1 = verticies[index+2], x2 = verticies[index+4];
var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5]; var y0 = verticies[index+1], y1 = verticies[index+3], y2 = verticies[index+5];
if(true) if(this.padding === 0)
{ {
//expand(); //expand();

View file

@ -186,7 +186,7 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
renderSession.spriteBatch.stop(); renderSession.spriteBatch.stop();
if (this._filters) renderSession.filterManager.popFilter(); if (this._filters) renderSession.filterManager.popFilter();
if (this._mask) renderSession.maskManager.popMask(renderSession); if (this._mask) renderSession.maskManager.popMask(this._mask, renderSession);
renderSession.spriteBatch.start(); renderSession.spriteBatch.start();
}; };
@ -452,4 +452,4 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
this.refreshTexture = false; this.refreshTexture = false;
this.tilingTexture.baseTexture._powerOf2 = true; this.tilingTexture.baseTexture._powerOf2 = true;
}; };

View file

@ -68,11 +68,7 @@ PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader;
PIXI.BitmapFontLoader.prototype.load = function() PIXI.BitmapFontLoader.prototype.load = function()
{ {
this.ajaxRequest = new PIXI.AjaxRequest(); this.ajaxRequest = new PIXI.AjaxRequest();
var scope = this; this.ajaxRequest.onreadystatechange = this.onXMLLoaded.bind(this);
this.ajaxRequest.onreadystatechange = function()
{
scope.onXMLLoaded();
};
this.ajaxRequest.open('GET', this.url, true); this.ajaxRequest.open('GET', this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType('application/xml'); if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType('application/xml');
@ -153,10 +149,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; image.addEventListener('loaded', this.onLoaded.bind(this));
image.addEventListener('loaded', function() {
scope.onLoaded();
});
image.load(); image.load();
} }
} }

View file

@ -4,7 +4,7 @@
/** /**
* The image loader class is responsible for loading images file formats ('jpeg', 'jpg', 'png' and 'gif') * The image loader class is responsible for loading images file formats ('jpeg', 'jpg', 'png' and 'gif')
* Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFrameId() * Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrame() and PIXI.Sprite.fromFrame()
* When loaded this class will dispatch a 'loaded' event * When loaded this class will dispatch a 'loaded' event
* *
* @class ImageLoader * @class ImageLoader
@ -45,11 +45,7 @@ PIXI.ImageLoader.prototype.load = function()
{ {
if(!this.texture.baseTexture.hasLoaded) if(!this.texture.baseTexture.hasLoaded)
{ {
var scope = this; this.texture.baseTexture.addEventListener('loaded', this.onLoaded.bind(this));
this.texture.baseTexture.addEventListener('loaded', function()
{
scope.onLoaded();
});
} }
else else
{ {
@ -88,7 +84,7 @@ PIXI.ImageLoader.prototype.loadFramedSpriteSheet = function(frameWidth, frameHei
{ {
for (var x=0; x<cols; x++,i++) for (var x=0; x<cols; x++,i++)
{ {
var texture = new PIXI.Texture(this.texture, { var texture = new PIXI.Texture(this.texture.baseTexture, {
x: x*frameWidth, x: x*frameWidth,
y: y*frameHeight, y: y*frameHeight,
width: frameWidth, width: frameWidth,
@ -100,15 +96,5 @@ PIXI.ImageLoader.prototype.loadFramedSpriteSheet = function(frameWidth, frameHei
} }
} }
if(!this.texture.baseTexture.hasLoaded) this.load();
{
var scope = this;
this.texture.baseTexture.addEventListener('loaded', function() {
scope.onLoaded();
});
}
else
{
this.onLoaded();
}
}; };

View file

@ -62,9 +62,7 @@ PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader;
*/ */
PIXI.JsonLoader.prototype.load = function () { PIXI.JsonLoader.prototype.load = function () {
var scope = this; if(window.XDomainRequest && this.crossorigin)
if(window.XDomainRequest && scope.crossorigin)
{ {
this.ajaxRequest = new window.XDomainRequest(); this.ajaxRequest = new window.XDomainRequest();
@ -73,13 +71,9 @@ PIXI.JsonLoader.prototype.load = function () {
// More info here: http://stackoverflow.com/questions/15786966/xdomainrequest-aborts-post-on-ie-9 // More info here: http://stackoverflow.com/questions/15786966/xdomainrequest-aborts-post-on-ie-9
this.ajaxRequest.timeout = 3000; this.ajaxRequest.timeout = 3000;
this.ajaxRequest.onerror = function () { this.ajaxRequest.onerror = this.onError.bind(this);
scope.onError();
}; this.ajaxRequest.ontimeout = this.onError.bind(this);
this.ajaxRequest.ontimeout = function () {
scope.onError();
};
this.ajaxRequest.onprogress = function() {}; this.ajaxRequest.onprogress = function() {};
@ -93,12 +87,9 @@ PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new window.ActiveXObject('Microsoft.XMLHTTP'); this.ajaxRequest = new window.ActiveXObject('Microsoft.XMLHTTP');
} }
this.ajaxRequest.onload = function(){
scope.onJSONLoaded(); this.ajaxRequest.onload = this.onJSONLoaded.bind(this);
};
this.ajaxRequest.open('GET',this.url,true); this.ajaxRequest.open('GET',this.url,true);
@ -112,27 +103,24 @@ PIXI.JsonLoader.prototype.load = function () {
* @private * @private
*/ */
PIXI.JsonLoader.prototype.onJSONLoaded = function () { PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if(!this.ajaxRequest.responseText ) if(!this.ajaxRequest.responseText )
{ {
this.onError(); this.onError();
return; return;
} }
this.json = JSON.parse(this.ajaxRequest.responseText); this.json = JSON.parse(this.ajaxRequest.responseText);
if(this.json.frames) if(this.json.frames)
{ {
// sprite sheet // sprite sheet
var scope = this;
var textureUrl = this.baseUrl + this.json.meta.image; var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin); var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames; var frameData = this.json.frames;
this.texture = image.texture.baseTexture; this.texture = image.texture.baseTexture;
image.addEventListener('loaded', function() { image.addEventListener('loaded', this.onLoaded.bind(this));
scope.onLoaded();
});
for (var i in frameData) for (var i in frameData)
{ {

View file

@ -453,7 +453,7 @@ PIXI.Graphics.prototype.drawPath = function(path)
{ {
if (!this.currentPath.points.length) this.graphicsData.pop(); if (!this.currentPath.points.length) this.graphicsData.pop();
this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY};
this.graphicsData.push(this.currentPath); this.graphicsData.push(this.currentPath);

View file

@ -78,14 +78,14 @@ PIXI.WebGLRenderer = function(width, height, view, transparent, antialias, prese
// deal with losing context.. // deal with losing context..
this.contextLost = this.handleContextLost.bind(this); this.contextLost = this.handleContextLost.bind(this);
this.contextRestoredLost = this.handleContextRestored.bind(this); this.contextRestoredLost = this.handleContextRestored.bind(this);
this.view.addEventListener('webglcontextlost', this.contextLost, false); this.view.addEventListener('webglcontextlost', this.contextLost, false);
this.view.addEventListener('webglcontextrestored', this.contextRestoredLost, false); this.view.addEventListener('webglcontextrestored', this.contextRestoredLost, false);
this.options = { this.options = {
alpha: this.transparent, alpha: this.transparent,
antialias:!!antialias, // SPEED UP?? antialias:!!antialias, // SPEED UP??
premultipliedAlpha:!!transparent, premultipliedAlpha:!!transparent && transparent !== 'notMultiplied',
stencil:true, stencil:true,
preserveDrawingBuffer: preserveDrawingBuffer preserveDrawingBuffer: preserveDrawingBuffer
}; };
@ -214,7 +214,7 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
stage.interactionManager.setTarget(this); stage.interactionManager.setTarget(this);
} }
} }
var gl = this.gl; var gl = this.gl;
// -- Does this need to be set every frame? -- // // -- Does this need to be set every frame? -- //
@ -285,7 +285,7 @@ PIXI.WebGLRenderer.prototype.render = function(stage)
* @method renderDIsplayObject * @method renderDIsplayObject
* @param displayObject {DisplayObject} The DisplayObject to render * @param displayObject {DisplayObject} The DisplayObject to render
* @param projection {Point} The projection * @param projection {Point} The projection
* @param buffer {Array} a standard WebGL buffer * @param buffer {Array} a standard WebGL buffer
*/ */
PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, projection, buffer) PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, projection, buffer)
{ {
@ -480,7 +480,7 @@ PIXI.updateWebGLTexture = function(texture, gl)
texture._dirty[gl.id] = false; texture._dirty[gl.id] = false;
} }
}; };
/** /**
@ -519,15 +519,19 @@ PIXI.WebGLRenderer.prototype.handleContextRestored = function()
} }
} }
PIXI.glContexts[this.glContextId] = null;
var gl = this.gl; var gl = this.gl;
gl.id = PIXI.WebGLRenderer.glContextId ++; this.glContextId = gl.id = PIXI.WebGLRenderer.glContextId++;
PIXI.glContexts[this.glContextId] = gl;
// need to set the context... // need to set the context...
this.shaderManager.setContext(gl); this.shaderManager.setContext(gl);
this.spriteBatch.setContext(gl); this.spriteBatch.setContext(gl);
this.primitiveBatch.setContext(gl); // this.primitiveBatch.setContext(gl);
this.maskManager.setContext(gl); this.maskManager.setContext(gl);
this.filterManager.setContext(gl); this.filterManager.setContext(gl);
@ -549,7 +553,7 @@ PIXI.WebGLRenderer.prototype.handleContextRestored = function()
} }
/** /**
* Whether the context was lost * Whether the context was lost
* @property contextLost * @property contextLost
* @type Boolean * @type Boolean
*/ */
@ -566,7 +570,7 @@ PIXI.WebGLRenderer.prototype.destroy = function()
{ {
// deal with losing context.. // deal with losing context..
// remove listeners // remove listeners
this.view.removeEventListener('webglcontextlost', this.contextLost); this.view.removeEventListener('webglcontextlost', this.contextLost);
this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost); this.view.removeEventListener('webglcontextrestored', this.contextRestoredLost);
@ -579,7 +583,7 @@ PIXI.WebGLRenderer.prototype.destroy = function()
// time to create the render managers! each one focuses on managine a state in webGL // time to create the render managers! each one focuses on managine a state in webGL
this.shaderManager.destroy(); this.shaderManager.destroy();
this.spriteBatch.destroy(); this.spriteBatch.destroy();
this.primitiveBatch.destroy(); // this.primitiveBatch.destroy();
this.maskManager.destroy(); this.maskManager.destroy();
this.filterManager.destroy(); this.filterManager.destroy();
@ -587,7 +591,7 @@ PIXI.WebGLRenderer.prototype.destroy = function()
this.spriteBatch = null; this.spriteBatch = null;
this.maskManager = null; this.maskManager = null;
this.filterManager = null; this.filterManager = null;
this.gl = null; this.gl = null;
// //
this.renderSession = null; this.renderSession = null;

View file

@ -102,5 +102,5 @@ PIXI.PrimitiveShader.prototype.destroy = function()
this.uniforms = null; this.uniforms = null;
this.gl = null; this.gl = null;
this.attribute = null; this.attributes = null;
}; };

View file

@ -86,3 +86,17 @@ PIXI.StripShader.prototype.init = function()
this.program = program; this.program = program;
}; };
/**
* Destroys the shader
* @method destroy
*
*/
PIXI.StripShader.prototype.destroy = function()
{
this.gl.deleteProgram( this.program );
this.uniforms = null;
this.gl = null;
this.attribute = null;
};

View file

@ -30,7 +30,7 @@ PIXI.FilterTexture = function(gl, width, height, scaleMode)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer ); gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer );
gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer ); gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer );
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0);

View file

@ -52,8 +52,6 @@ PIXI.WebGLGraphics.renderGraphics = function(graphics, renderSession)//projectio
gl.drawElements(gl.TRIANGLE_FAN, 4, gl.UNSIGNED_SHORT, ( webGLData.indices.length - 4 ) * 2 ); gl.drawElements(gl.TRIANGLE_FAN, 4, gl.UNSIGNED_SHORT, ( webGLData.indices.length - 4 ) * 2 );
renderSession.stencilManager.popStencil(graphics, webGLData, renderSession); renderSession.stencilManager.popStencil(graphics, webGLData, renderSession);
this.last = webGLData.mode;
} }
else else
{ {

View file

@ -10,13 +10,7 @@
*/ */
PIXI.WebGLMaskManager = function(gl) PIXI.WebGLMaskManager = function(gl)
{ {
this.maskStack = [];
this.maskPosition = 0;
this.setContext(gl); this.setContext(gl);
this.reverse = false;
this.count = 0;
}; };
/** /**
@ -68,6 +62,5 @@ PIXI.WebGLMaskManager.prototype.popMask = function(maskData, renderSession)
*/ */
PIXI.WebGLMaskManager.prototype.destroy = function() PIXI.WebGLMaskManager.prototype.destroy = function()
{ {
this.maskStack = null;
this.gl = null; this.gl = null;
}; };

View file

@ -14,7 +14,6 @@ PIXI.WebGLShaderManager = function(gl)
this.maxAttibs = 10; this.maxAttibs = 10;
this.attribState = []; this.attribState = [];
this.tempAttribState = []; this.tempAttribState = [];
this.shaderMap = [];
for (var i = 0; i < this.maxAttibs; i++) { for (var i = 0; i < this.maxAttibs; i++) {
this.attribState[i] = false; this.attribState[i] = false;
@ -39,7 +38,7 @@ PIXI.WebGLShaderManager.prototype.setContext = function(gl)
this.primitiveShader = new PIXI.PrimitiveShader(gl); this.primitiveShader = new PIXI.PrimitiveShader(gl);
// the next one is used for rendering triangle strips // the next one is used for rendering triangle strips
this.complexPrimativeShader = new PIXI.ComplexPrimitiveShader(gl); this.complexPrimitiveShader = new PIXI.ComplexPrimitiveShader(gl);
// this shader is used for the default sprite rendering // this shader is used for the default sprite rendering
this.defaultShader = new PIXI.PixiShader(gl); this.defaultShader = new PIXI.PixiShader(gl);
@ -122,6 +121,8 @@ PIXI.WebGLShaderManager.prototype.destroy = function()
this.primitiveShader.destroy(); this.primitiveShader.destroy();
this.complexPrimitiveShader.destroy();
this.defaultShader.destroy(); this.defaultShader.destroy();
this.fastShader.destroy(); this.fastShader.destroy();

View file

@ -138,7 +138,7 @@ PIXI.WebGLStencilManager.prototype.bindGraphics = function(graphics, webGLData,
if(webGLData.mode === 1) if(webGLData.mode === 1)
{ {
shader = renderSession.shaderManager.complexPrimativeShader; shader = renderSession.shaderManager.complexPrimitiveShader;
renderSession.shaderManager.setShader( shader ); renderSession.shaderManager.setShader( shader );
@ -283,6 +283,6 @@ PIXI.WebGLStencilManager.prototype.popStencil = function(graphics, webGLData, re
*/ */
PIXI.WebGLStencilManager.prototype.destroy = function() PIXI.WebGLStencilManager.prototype.destroy = function()
{ {
this.maskStack = null; this.stencilStack = null;
this.gl = null; this.gl = null;
}; };

View file

@ -129,7 +129,6 @@ PIXI.Text.prototype.setStyle = function(style)
style.strokeThickness = style.strokeThickness || 0; style.strokeThickness = style.strokeThickness || 0;
style.wordWrap = style.wordWrap || false; style.wordWrap = style.wordWrap || false;
style.wordWrapWidth = style.wordWrapWidth || 100; style.wordWrapWidth = style.wordWrapWidth || 100;
style.wordWrapWidth = style.wordWrapWidth || 100;
style.dropShadow = style.dropShadow || false; style.dropShadow = style.dropShadow || false;
style.dropShadowAngle = style.dropShadowAngle || Math.PI / 6; style.dropShadowAngle = style.dropShadowAngle || Math.PI / 6;

View file

@ -78,10 +78,10 @@ PIXI.BaseTexture = function(source, scaleMode)
// used for webGL // used for webGL
this._glTextures = []; this._glTextures = [];
// used for webGL teture updateing... // used for webGL teture updateing...
this._dirty = []; this._dirty = [];
if(!source)return; if(!source)return;
if((this.source.complete || this.source.getContext) && this.source.width && this.source.height) if((this.source.complete || this.source.getContext) && this.source.width && this.source.height)
@ -118,7 +118,7 @@ PIXI.BaseTexture = function(source, scaleMode)
this.imageUrl = null; this.imageUrl = null;
this._powerOf2 = false; this._powerOf2 = false;
}; };
@ -166,14 +166,14 @@ PIXI.BaseTexture.prototype.updateSourceImage = function(newSrc)
* @static * @static
* @method fromImage * @method fromImage
* @param imageUrl {String} The image url of the texture * @param imageUrl {String} The image url of the texture
* @param crossorigin {Boolean} * @param crossorigin {Boolean}
* @param scaleMode {Number} Should be one of the PIXI.scaleMode consts * @param scaleMode {Number} Should be one of the PIXI.scaleMode consts
* @return BaseTexture * @return BaseTexture
*/ */
PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin, scaleMode) PIXI.BaseTexture.fromImage = function(imageUrl, crossorigin, scaleMode)
{ {
var baseTexture = PIXI.BaseTextureCache[imageUrl]; var baseTexture = PIXI.BaseTextureCache[imageUrl];
if(crossorigin === undefined && imageUrl.indexOf('data:') === -1) crossorigin = true; if(crossorigin === undefined && imageUrl.indexOf('data:') === -1) crossorigin = true;
if(!baseTexture) if(!baseTexture)

View file

@ -35,6 +35,7 @@ PIXI.RenderTexture = function(width, height, renderer, scaleMode)
{ {
PIXI.EventTarget.call( this ); PIXI.EventTarget.call( this );
/** /**
* The with of the render texture * The with of the render texture
* *
@ -126,6 +127,9 @@ PIXI.RenderTexture.prototype.resize = function(width, height, updateBase)
return; return;
} }
this.valid = (width > 0 && height > 0);
this.width = this.frame.width = this.crop.width = width; this.width = this.frame.width = this.crop.width = width;
this.height = this.frame.height = this.crop.height = height; this.height = this.frame.height = this.crop.height = height;
@ -141,7 +145,9 @@ PIXI.RenderTexture.prototype.resize = function(width, height, updateBase)
this.projection.y = -this.height / 2; this.projection.y = -this.height / 2;
} }
if(!this.valid)return;
this.textureBuffer.resize(this.width, this.height); this.textureBuffer.resize(this.width, this.height);
}; };
/** /**
@ -151,6 +157,8 @@ PIXI.RenderTexture.prototype.resize = function(width, height, updateBase)
*/ */
PIXI.RenderTexture.prototype.clear = function() PIXI.RenderTexture.prototype.clear = function()
{ {
if(!this.valid)return;
if (this.renderer.type === PIXI.WEBGL_RENDERER) if (this.renderer.type === PIXI.WEBGL_RENDERER)
{ {
this.renderer.gl.bindFramebuffer(this.renderer.gl.FRAMEBUFFER, this.textureBuffer.frameBuffer); this.renderer.gl.bindFramebuffer(this.renderer.gl.FRAMEBUFFER, this.textureBuffer.frameBuffer);
@ -169,6 +177,7 @@ PIXI.RenderTexture.prototype.clear = function()
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear)
{ {
if(!this.valid)return;
//TOOD replace position with matrix.. //TOOD replace position with matrix..
var gl = this.renderer.gl; var gl = this.renderer.gl;
@ -225,6 +234,8 @@ PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, position, cle
*/ */
PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, position, clear) PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, position, clear)
{ {
if(!this.valid)return;
var children = displayObject.children; var children = displayObject.children;
var originalWorldTransform = displayObject.worldTransform; var originalWorldTransform = displayObject.worldTransform;
@ -258,5 +269,64 @@ PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, position, cl
displayObject.worldTransform = originalWorldTransform; displayObject.worldTransform = originalWorldTransform;
}; };
/**
* Will return a HTML Image of the texture
*
* @method getImage
*/
PIXI.RenderTexture.prototype.getImage = function()
{
var image = new Image();
image.src = this.getBase64();
return image;
};
/**
* Will return a a base64 string of the texture
*
* @method getImage
*/
PIXI.RenderTexture.prototype.getBase64 = function()
{
return this.getCanvas().toDataURL();
};
PIXI.RenderTexture.prototype.getCanvas = function()
{
if (this.renderer.type === PIXI.WEBGL_RENDERER)
{
var gl = this.renderer.gl;
var width = this.textureBuffer.width;
var height = this.textureBuffer.height;
var webGLPixels = new Uint8Array(4 * width * height);
gl.bindFramebuffer(gl.FRAMEBUFFER, this.textureBuffer.frameBuffer);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, webGLPixels);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
var tempCanvas = new PIXI.CanvasBuffer(width, height);
var canvasData = tempCanvas.context.getImageData(0, 0, width, height);
var canvasPixels = canvasData.data;
for (var i = 0; i < webGLPixels.length; i+=4)
{
var alpha = webGLPixels[i+3];
canvasPixels[i] = webGLPixels[i] * alpha;
canvasPixels[i+1] = webGLPixels[i+1] * alpha;
canvasPixels[i+2] = webGLPixels[i+2] * alpha;
canvasPixels[i+3] = alpha;
}
tempCanvas.context.putImageData(canvasData, 0, 0);
return tempCanvas.canvas;
}
else
{
return this.textureBuffer.canvas;
}
};
PIXI.RenderTexture.tempMatrix = new PIXI.Matrix(); PIXI.RenderTexture.tempMatrix = new PIXI.Matrix();

View file

@ -63,7 +63,7 @@ PIXI.Texture = function(baseTexture, frame)
* @type Rectangle * @type Rectangle
*/ */
this.trim = null; this.trim = null;
/** /**
* This will let the renderer know if the texture is valid. If its not then it cannot be rendered. * This will let the renderer know if the texture is valid. If its not then it cannot be rendered.
* *
@ -72,14 +72,6 @@ PIXI.Texture = function(baseTexture, frame)
*/ */
this.valid = false; this.valid = false;
/**
* The context scope under which events are run.
*
* @property scope
* @type Object
*/
this.scope = this;
/** /**
* The WebGL UV data cache. * The WebGL UV data cache.
* *
@ -88,7 +80,7 @@ PIXI.Texture = function(baseTexture, frame)
* @type Object * @type Object
*/ */
this._uvs = null; this._uvs = null;
/** /**
* The width of the Texture in pixels. * The width of the Texture in pixels.
* *
@ -121,8 +113,7 @@ PIXI.Texture = function(baseTexture, frame)
} }
else else
{ {
var scope = this; baseTexture.addEventListener('loaded', this.onBaseTextureLoaded.bind(this));
baseTexture.addEventListener('loaded', function(){ scope.onBaseTextureLoaded(); });
} }
}; };
@ -141,10 +132,10 @@ PIXI.Texture.prototype.onBaseTextureLoaded = function()
baseTexture.removeEventListener('loaded', this.onLoaded); baseTexture.removeEventListener('loaded', this.onLoaded);
if (this.noFrame) this.frame = new PIXI.Rectangle(0, 0, baseTexture.width, baseTexture.height); if (this.noFrame) this.frame = new PIXI.Rectangle(0, 0, baseTexture.width, baseTexture.height);
this.setFrame(this.frame); this.setFrame(this.frame);
this.scope.dispatchEvent( { type: 'update', content: this } ); this.dispatchEvent( { type: 'update', content: this } );
}; };
/** /**

View file

@ -13,9 +13,10 @@
* @param [view] {Canvas} the canvas to use as a view, optional * @param [view] {Canvas} the canvas to use as a view, optional
* @param [transparent=false] {Boolean} the transparency of the render view, default false * @param [transparent=false] {Boolean} the transparency of the render view, default false
* @param [antialias=false] {Boolean} sets antialias (only applicable in webGL chrome at the moment) * @param [antialias=false] {Boolean} sets antialias (only applicable in webGL chrome at the moment)
* @param [preserveDrawingBuffer=false] {Boolean} enables drawing buffer preservation, enable this if you need to call toDataUrl on the webgl context
* *
*/ */
PIXI.autoDetectRenderer = function(width, height, view, transparent, antialias) PIXI.autoDetectRenderer = function(width, height, view, transparent, antialias, preserveDrawingBuffer)
{ {
if(!width)width = 800; if(!width)width = 800;
if(!height)height = 600; if(!height)height = 600;
@ -31,7 +32,7 @@ PIXI.autoDetectRenderer = function(width, height, view, transparent, antialias)
if( webgl ) if( webgl )
{ {
return new PIXI.WebGLRenderer(width, height, view, transparent, antialias); return new PIXI.WebGLRenderer(width, height, view, transparent, antialias, preserveDrawingBuffer);
} }
return new PIXI.CanvasRenderer(width, height, view, transparent); return new PIXI.CanvasRenderer(width, height, view, transparent);
@ -49,9 +50,10 @@ PIXI.autoDetectRenderer = function(width, height, view, transparent, antialias)
* @param [view] {Canvas} the canvas to use as a view, optional * @param [view] {Canvas} the canvas to use as a view, optional
* @param [transparent=false] {Boolean} the transparency of the render view, default false * @param [transparent=false] {Boolean} the transparency of the render view, default false
* @param [antialias=false] {Boolean} sets antialias (only applicable in webGL chrome at the moment) * @param [antialias=false] {Boolean} sets antialias (only applicable in webGL chrome at the moment)
* @param [preserveDrawingBuffer=false] {Boolean} enables drawing buffer preservation, enable this if you need to call toDataUrl on the webgl context
* *
*/ */
PIXI.autoDetectRecommendedRenderer = function(width, height, view, transparent, antialias) PIXI.autoDetectRecommendedRenderer = function(width, height, view, transparent, antialias, preserveDrawingBuffer)
{ {
if(!width)width = 800; if(!width)width = 800;
if(!height)height = 600; if(!height)height = 600;
@ -69,7 +71,7 @@ PIXI.autoDetectRecommendedRenderer = function(width, height, view, transparent,
if( webgl && !isAndroid) if( webgl && !isAndroid)
{ {
return new PIXI.WebGLRenderer(width, height, view, transparent, antialias); return new PIXI.WebGLRenderer(width, height, view, transparent, antialias, preserveDrawingBuffer);
} }
return new PIXI.CanvasRenderer(width, height, view, transparent); return new PIXI.CanvasRenderer(width, height, view, transparent);

View file

@ -21,32 +21,34 @@
* *
* @method cancelAnimationFrame * @method cancelAnimationFrame
*/ */
var lastTime = 0; (function(window) {
var vendors = ['ms', 'moz', 'webkit', 'o']; var lastTime = 0;
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { var vendors = ['ms', 'moz', 'webkit', 'o'];
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window[vendors[x] + 'CancelRequestAnimationFrame']; window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||
} window[vendors[x] + 'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame) { if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(callback) { window.requestAnimationFrame = function(callback) {
var currTime = new Date().getTime(); var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() { callback(currTime + timeToCall); }, var id = window.setTimeout(function() { callback(currTime + timeToCall); },
timeToCall); timeToCall);
lastTime = currTime + timeToCall; lastTime = currTime + timeToCall;
return id; return id;
}; };
} }
if (!window.cancelAnimationFrame) { if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) { window.cancelAnimationFrame = function(id) {
clearTimeout(id); clearTimeout(id);
}; };
} }
window.requestAnimFrame = window.requestAnimationFrame; window.requestAnimFrame = window.requestAnimationFrame;
})(this);
/** /**
* Converts a hex color number to an [R, G, B] array * Converts a hex color number to an [R, G, B] array
@ -75,14 +77,20 @@ PIXI.rgb2hex = function(rgb) {
*/ */
if (typeof Function.prototype.bind !== 'function') { if (typeof Function.prototype.bind !== 'function') {
Function.prototype.bind = (function () { Function.prototype.bind = (function () {
var slice = Array.prototype.slice;
return function (thisArg) { return function (thisArg) {
var target = this, boundArgs = slice.call(arguments, 1); var target = this, i = arguments.length - 1, boundArgs = [];
if (i > 0)
{
boundArgs.length = i;
while (i--) boundArgs[i] = arguments[i + 1];
}
if (typeof target !== 'function') throw new TypeError(); if (typeof target !== 'function') throw new TypeError();
function bound() { function bound() {
var args = boundArgs.concat(slice.call(arguments)); var i = arguments.length, args = new Array(i);
while (i--) args[i] = arguments[i];
args = boundArgs.concat(args);
target.apply(this instanceof bound ? this : thisArg, args); target.apply(this instanceof bound ? this : thisArg, args);
} }
@ -164,6 +172,7 @@ PIXI.unpackColorRGB = function(r, g, b)//r, g, b, a)
*/ */
PIXI.canUseNewCanvasBlendModes = function() PIXI.canUseNewCanvasBlendModes = function()
{ {
if (typeof document === 'undefined') return false;
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.width = 1; canvas.width = 1;
canvas.height = 1; canvas.height = 1;