mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 15:12:18 +00:00
Updated to latest version of Pixi.
This commit is contained in:
parent
ffb413b741
commit
cca955f1fd
28 changed files with 400 additions and 200 deletions
|
@ -41,9 +41,10 @@ PIXI.InteractionData = function()
|
|||
*
|
||||
* @method getLocalPosition
|
||||
* @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
|
||||
*/
|
||||
PIXI.InteractionData.prototype.getLocalPosition = function(displayObject)
|
||||
PIXI.InteractionData.prototype.getLocalPosition = function(displayObject, point)
|
||||
{
|
||||
var worldTransform = displayObject.worldTransform;
|
||||
var global = this.global;
|
||||
|
@ -52,9 +53,14 @@ PIXI.InteractionData.prototype.getLocalPosition = function(displayObject)
|
|||
var a00 = worldTransform.a, a01 = worldTransform.b, a02 = worldTransform.tx,
|
||||
a10 = worldTransform.c, a11 = worldTransform.d, a12 = worldTransform.ty,
|
||||
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...
|
||||
return new PIXI.Point(a11 * id * global.x + -a01 * id * global.y + (a12 * a01 - a02 * a11) * id,
|
||||
a00 * id * global.y + -a10 * id * global.x + (-a12 * a00 + a02 * a10) * id);
|
||||
return point;
|
||||
};
|
||||
|
||||
// constructor
|
||||
|
|
|
@ -381,22 +381,29 @@ PIXI.InteractionManager.prototype.onMouseDown = function(event)
|
|||
//stage.__i
|
||||
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
|
||||
// hit test
|
||||
for (var i = 0; i < length; 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);
|
||||
|
||||
if(item.__hit)
|
||||
{
|
||||
//call the function!
|
||||
if(item.mousedown)item.mousedown(this.mouse);
|
||||
item.__isDown = true;
|
||||
if(item[downFunction])item[downFunction](this.mouse);
|
||||
item[isDown] = true;
|
||||
|
||||
// just the one!
|
||||
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
|
||||
* @private
|
||||
*/
|
||||
PIXI.InteractionManager.prototype.onMouseOut = function()
|
||||
PIXI.InteractionManager.prototype.onMouseOut = function(event)
|
||||
{
|
||||
if(this.dirty)
|
||||
{
|
||||
this.rebuildInteractiveGraph();
|
||||
}
|
||||
|
||||
this.mouse.originalEvent = event || window.event; //IE uses window.event
|
||||
|
||||
var length = this.interactiveItems.length;
|
||||
|
||||
this.interactionDOMElement.style.cursor = 'inherit';
|
||||
|
@ -460,36 +469,46 @@ PIXI.InteractionManager.prototype.onMouseUp = function(event)
|
|||
var length = this.interactiveItems.length;
|
||||
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++)
|
||||
{
|
||||
var item = this.interactiveItems[i];
|
||||
|
||||
if(item[clickFunction] || item[upFunction] || item[upOutsideFunction])
|
||||
{
|
||||
item.__hit = this.hitTest(item, this.mouse);
|
||||
|
||||
if(item.__hit && !up)
|
||||
{
|
||||
//call the function!
|
||||
if(item.mouseup)
|
||||
if(item[upFunction])
|
||||
{
|
||||
item.mouseup(this.mouse);
|
||||
item[upFunction](this.mouse);
|
||||
}
|
||||
if(item.__isDown)
|
||||
if(item[isDown])
|
||||
{
|
||||
if(item.click)item.click(this.mouse);
|
||||
if(item[clickFunction])item[clickFunction](this.mouse);
|
||||
}
|
||||
|
||||
if(!item.interactiveChildren)up = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(item.__isDown)
|
||||
if(item[isDown])
|
||||
{
|
||||
if(item.mouseupoutside)item.mouseupoutside(this.mouse);
|
||||
if(item[upOutsideFunction])item[upOutsideFunction](this.mouse);
|
||||
}
|
||||
}
|
||||
|
||||
item.__isDown = false;
|
||||
//}
|
||||
item[isDown] = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -596,7 +615,8 @@ PIXI.InteractionManager.prototype.onTouchMove = function(event)
|
|||
// update the touch position
|
||||
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
|
||||
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.y = touchEvent.clientY;
|
||||
}
|
||||
|
@ -640,7 +660,8 @@ PIXI.InteractionManager.prototype.onTouchStart = function(event)
|
|||
this.touchs[touchEvent.identifier] = touchData;
|
||||
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
|
||||
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.y = touchEvent.clientY;
|
||||
}
|
||||
|
@ -695,7 +716,8 @@ PIXI.InteractionManager.prototype.onTouchEnd = function(event)
|
|||
var up = false;
|
||||
touchData.global.x = (touchEvent.clientX - rect.left) * (this.target.width / rect.width);
|
||||
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.y = touchEvent.clientY;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ PIXI.Circle.prototype.contains = function(x, y)
|
|||
*/
|
||||
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
|
||||
|
|
|
@ -78,6 +78,45 @@ PIXI.Matrix.prototype.toArray = function(transpose)
|
|||
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.determineMatrixArrayType = function() {
|
||||
|
|
|
@ -204,32 +204,6 @@ PIXI.DisplayObject = function()
|
|||
* 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
|
||||
* @method mouseover
|
||||
|
@ -242,6 +216,59 @@ PIXI.DisplayObject = function()
|
|||
* @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
|
||||
|
@ -481,7 +508,6 @@ PIXI.DisplayObject.prototype.getLocalBounds = function()
|
|||
return this.getBounds(PIXI.identityMatrix);///PIXI.EmptyRectangle();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the object's stage reference, the stage this object is connected to
|
||||
*
|
||||
|
@ -509,6 +535,37 @@ PIXI.DisplayObject.prototype.updateCache = function()
|
|||
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)
|
||||
{
|
||||
this._cachedSprite.worldAlpha = this.worldAlpha;
|
||||
|
|
|
@ -226,6 +226,10 @@ PIXI.DisplayObjectContainer.prototype.removeChildren = function(beginIndex, endI
|
|||
}
|
||||
return removed;
|
||||
}
|
||||
else if (range === 0 && this.children.length === 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Error( 'Range Error, numeric values are outside the acceptable range' );
|
||||
|
|
|
@ -308,7 +308,7 @@ PIXI.Sprite.prototype._renderWebGL = 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 (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)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*
|
||||
* @class Rope
|
||||
* @constructor
|
||||
* @extends Strip
|
||||
* @param texture {Texture} The texture to use
|
||||
* @param points {Array}
|
||||
*
|
||||
|
|
|
@ -16,6 +16,13 @@ PIXI.Strip = function(texture)
|
|||
{
|
||||
PIXI.DisplayObjectContainer.call( this );
|
||||
|
||||
|
||||
/**
|
||||
* The texture of the strip
|
||||
*
|
||||
* @property texture
|
||||
* @type Texture
|
||||
*/
|
||||
this.texture = texture;
|
||||
|
||||
// set up the main bits..
|
||||
|
@ -33,8 +40,24 @@ PIXI.Strip = function(texture)
|
|||
|
||||
this.indices = new PIXI.Uint16Array([0, 1, 2, 3]);
|
||||
|
||||
|
||||
/**
|
||||
* Whether the strip is dirty or not
|
||||
*
|
||||
* @property dirty
|
||||
* @type Boolean
|
||||
*/
|
||||
this.dirty = true;
|
||||
|
||||
|
||||
/**
|
||||
* if you need a padding, not yet implemented
|
||||
*
|
||||
* @property padding
|
||||
* @type Number
|
||||
*/
|
||||
this.padding = 0;
|
||||
// NYI, TODO padding ?
|
||||
|
||||
};
|
||||
|
||||
// constructor
|
||||
|
@ -184,7 +207,7 @@ PIXI.Strip.prototype._renderCanvas = function(renderSession)
|
|||
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];
|
||||
|
||||
if(true)
|
||||
if(this.padding === 0)
|
||||
{
|
||||
|
||||
//expand();
|
||||
|
|
|
@ -186,7 +186,7 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
|||
renderSession.spriteBatch.stop();
|
||||
|
||||
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();
|
||||
};
|
||||
|
|
|
@ -68,11 +68,7 @@ PIXI.BitmapFontLoader.prototype.constructor = PIXI.BitmapFontLoader;
|
|||
PIXI.BitmapFontLoader.prototype.load = function()
|
||||
{
|
||||
this.ajaxRequest = new PIXI.AjaxRequest();
|
||||
var scope = this;
|
||||
this.ajaxRequest.onreadystatechange = function()
|
||||
{
|
||||
scope.onXMLLoaded();
|
||||
};
|
||||
this.ajaxRequest.onreadystatechange = this.onXMLLoaded.bind(this);
|
||||
|
||||
this.ajaxRequest.open('GET', this.url, true);
|
||||
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType('application/xml');
|
||||
|
@ -153,10 +149,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
|
|||
|
||||
PIXI.BitmapText.fonts[data.font] = data;
|
||||
|
||||
var scope = this;
|
||||
image.addEventListener('loaded', function() {
|
||||
scope.onLoaded();
|
||||
});
|
||||
image.addEventListener('loaded', this.onLoaded.bind(this));
|
||||
image.load();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @class ImageLoader
|
||||
|
@ -45,11 +45,7 @@ PIXI.ImageLoader.prototype.load = function()
|
|||
{
|
||||
if(!this.texture.baseTexture.hasLoaded)
|
||||
{
|
||||
var scope = this;
|
||||
this.texture.baseTexture.addEventListener('loaded', function()
|
||||
{
|
||||
scope.onLoaded();
|
||||
});
|
||||
this.texture.baseTexture.addEventListener('loaded', this.onLoaded.bind(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -88,7 +84,7 @@ PIXI.ImageLoader.prototype.loadFramedSpriteSheet = function(frameWidth, frameHei
|
|||
{
|
||||
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,
|
||||
y: y*frameHeight,
|
||||
width: frameWidth,
|
||||
|
@ -100,15 +96,5 @@ PIXI.ImageLoader.prototype.loadFramedSpriteSheet = function(frameWidth, frameHei
|
|||
}
|
||||
}
|
||||
|
||||
if(!this.texture.baseTexture.hasLoaded)
|
||||
{
|
||||
var scope = this;
|
||||
this.texture.baseTexture.addEventListener('loaded', function() {
|
||||
scope.onLoaded();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.onLoaded();
|
||||
}
|
||||
this.load();
|
||||
};
|
||||
|
|
|
@ -62,9 +62,7 @@ PIXI.JsonLoader.prototype.constructor = PIXI.JsonLoader;
|
|||
*/
|
||||
PIXI.JsonLoader.prototype.load = function () {
|
||||
|
||||
var scope = this;
|
||||
|
||||
if(window.XDomainRequest && scope.crossorigin)
|
||||
if(window.XDomainRequest && this.crossorigin)
|
||||
{
|
||||
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
|
||||
this.ajaxRequest.timeout = 3000;
|
||||
|
||||
this.ajaxRequest.onerror = function () {
|
||||
scope.onError();
|
||||
};
|
||||
this.ajaxRequest.onerror = this.onError.bind(this);
|
||||
|
||||
this.ajaxRequest.ontimeout = function () {
|
||||
scope.onError();
|
||||
};
|
||||
this.ajaxRequest.ontimeout = this.onError.bind(this);
|
||||
|
||||
this.ajaxRequest.onprogress = function() {};
|
||||
|
||||
|
@ -95,10 +89,7 @@ PIXI.JsonLoader.prototype.load = function () {
|
|||
|
||||
|
||||
|
||||
this.ajaxRequest.onload = function(){
|
||||
|
||||
scope.onJSONLoaded();
|
||||
};
|
||||
this.ajaxRequest.onload = this.onJSONLoaded.bind(this);
|
||||
|
||||
this.ajaxRequest.open('GET',this.url,true);
|
||||
|
||||
|
@ -124,15 +115,12 @@ PIXI.JsonLoader.prototype.onJSONLoaded = function () {
|
|||
if(this.json.frames)
|
||||
{
|
||||
// sprite sheet
|
||||
var scope = this;
|
||||
var textureUrl = this.baseUrl + this.json.meta.image;
|
||||
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
|
||||
var frameData = this.json.frames;
|
||||
|
||||
this.texture = image.texture.baseTexture;
|
||||
image.addEventListener('loaded', function() {
|
||||
scope.onLoaded();
|
||||
});
|
||||
image.addEventListener('loaded', this.onLoaded.bind(this));
|
||||
|
||||
for (var i in frameData)
|
||||
{
|
||||
|
|
|
@ -453,7 +453,7 @@ PIXI.Graphics.prototype.drawPath = function(path)
|
|||
{
|
||||
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};
|
||||
|
||||
this.graphicsData.push(this.currentPath);
|
||||
|
|
|
@ -85,7 +85,7 @@ PIXI.WebGLRenderer = function(width, height, view, transparent, antialias, prese
|
|||
this.options = {
|
||||
alpha: this.transparent,
|
||||
antialias:!!antialias, // SPEED UP??
|
||||
premultipliedAlpha:!!transparent,
|
||||
premultipliedAlpha:!!transparent && transparent !== 'notMultiplied',
|
||||
stencil:true,
|
||||
preserveDrawingBuffer: preserveDrawingBuffer
|
||||
};
|
||||
|
@ -519,15 +519,19 @@ PIXI.WebGLRenderer.prototype.handleContextRestored = function()
|
|||
}
|
||||
}
|
||||
|
||||
PIXI.glContexts[this.glContextId] = null;
|
||||
|
||||
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...
|
||||
this.shaderManager.setContext(gl);
|
||||
this.spriteBatch.setContext(gl);
|
||||
this.primitiveBatch.setContext(gl);
|
||||
// this.primitiveBatch.setContext(gl);
|
||||
this.maskManager.setContext(gl);
|
||||
this.filterManager.setContext(gl);
|
||||
|
||||
|
@ -579,7 +583,7 @@ PIXI.WebGLRenderer.prototype.destroy = function()
|
|||
// time to create the render managers! each one focuses on managine a state in webGL
|
||||
this.shaderManager.destroy();
|
||||
this.spriteBatch.destroy();
|
||||
this.primitiveBatch.destroy();
|
||||
// this.primitiveBatch.destroy();
|
||||
this.maskManager.destroy();
|
||||
this.filterManager.destroy();
|
||||
|
||||
|
|
|
@ -102,5 +102,5 @@ PIXI.PrimitiveShader.prototype.destroy = function()
|
|||
this.uniforms = null;
|
||||
this.gl = null;
|
||||
|
||||
this.attribute = null;
|
||||
this.attributes = null;
|
||||
};
|
||||
|
|
|
@ -86,3 +86,17 @@ PIXI.StripShader.prototype.init = function()
|
|||
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -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_WRAP_S, 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.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0);
|
||||
|
|
|
@ -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 );
|
||||
|
||||
renderSession.stencilManager.popStencil(graphics, webGLData, renderSession);
|
||||
|
||||
this.last = webGLData.mode;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -10,13 +10,7 @@
|
|||
*/
|
||||
PIXI.WebGLMaskManager = function(gl)
|
||||
{
|
||||
this.maskStack = [];
|
||||
this.maskPosition = 0;
|
||||
|
||||
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()
|
||||
{
|
||||
this.maskStack = null;
|
||||
this.gl = null;
|
||||
};
|
|
@ -14,7 +14,6 @@ PIXI.WebGLShaderManager = function(gl)
|
|||
this.maxAttibs = 10;
|
||||
this.attribState = [];
|
||||
this.tempAttribState = [];
|
||||
this.shaderMap = [];
|
||||
|
||||
for (var i = 0; i < this.maxAttibs; i++) {
|
||||
this.attribState[i] = false;
|
||||
|
@ -39,7 +38,7 @@ PIXI.WebGLShaderManager.prototype.setContext = function(gl)
|
|||
this.primitiveShader = new PIXI.PrimitiveShader(gl);
|
||||
|
||||
// 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.defaultShader = new PIXI.PixiShader(gl);
|
||||
|
@ -122,6 +121,8 @@ PIXI.WebGLShaderManager.prototype.destroy = function()
|
|||
|
||||
this.primitiveShader.destroy();
|
||||
|
||||
this.complexPrimitiveShader.destroy();
|
||||
|
||||
this.defaultShader.destroy();
|
||||
|
||||
this.fastShader.destroy();
|
||||
|
|
|
@ -138,7 +138,7 @@ PIXI.WebGLStencilManager.prototype.bindGraphics = function(graphics, webGLData,
|
|||
|
||||
if(webGLData.mode === 1)
|
||||
{
|
||||
shader = renderSession.shaderManager.complexPrimativeShader;
|
||||
shader = renderSession.shaderManager.complexPrimitiveShader;
|
||||
|
||||
renderSession.shaderManager.setShader( shader );
|
||||
|
||||
|
@ -283,6 +283,6 @@ PIXI.WebGLStencilManager.prototype.popStencil = function(graphics, webGLData, re
|
|||
*/
|
||||
PIXI.WebGLStencilManager.prototype.destroy = function()
|
||||
{
|
||||
this.maskStack = null;
|
||||
this.stencilStack = null;
|
||||
this.gl = null;
|
||||
};
|
|
@ -129,7 +129,6 @@ PIXI.Text.prototype.setStyle = function(style)
|
|||
style.strokeThickness = style.strokeThickness || 0;
|
||||
style.wordWrap = style.wordWrap || false;
|
||||
style.wordWrapWidth = style.wordWrapWidth || 100;
|
||||
style.wordWrapWidth = style.wordWrapWidth || 100;
|
||||
|
||||
style.dropShadow = style.dropShadow || false;
|
||||
style.dropShadowAngle = style.dropShadowAngle || Math.PI / 6;
|
||||
|
|
|
@ -35,6 +35,7 @@ PIXI.RenderTexture = function(width, height, renderer, scaleMode)
|
|||
{
|
||||
PIXI.EventTarget.call( this );
|
||||
|
||||
|
||||
/**
|
||||
* The with of the render texture
|
||||
*
|
||||
|
@ -126,6 +127,9 @@ PIXI.RenderTexture.prototype.resize = function(width, height, updateBase)
|
|||
return;
|
||||
}
|
||||
|
||||
this.valid = (width > 0 && height > 0);
|
||||
|
||||
|
||||
this.width = this.frame.width = this.crop.width = width;
|
||||
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;
|
||||
}
|
||||
|
||||
if(!this.valid)return;
|
||||
this.textureBuffer.resize(this.width, this.height);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -151,6 +157,8 @@ PIXI.RenderTexture.prototype.resize = function(width, height, updateBase)
|
|||
*/
|
||||
PIXI.RenderTexture.prototype.clear = function()
|
||||
{
|
||||
if(!this.valid)return;
|
||||
|
||||
if (this.renderer.type === PIXI.WEBGL_RENDERER)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if(!this.valid)return;
|
||||
//TOOD replace position with matrix..
|
||||
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)
|
||||
{
|
||||
if(!this.valid)return;
|
||||
|
||||
var children = displayObject.children;
|
||||
|
||||
var originalWorldTransform = displayObject.worldTransform;
|
||||
|
@ -258,5 +269,64 @@ PIXI.RenderTexture.prototype.renderCanvas = function(displayObject, position, cl
|
|||
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();
|
||||
|
||||
|
|
|
@ -72,14 +72,6 @@ PIXI.Texture = function(baseTexture, frame)
|
|||
*/
|
||||
this.valid = false;
|
||||
|
||||
/**
|
||||
* The context scope under which events are run.
|
||||
*
|
||||
* @property scope
|
||||
* @type Object
|
||||
*/
|
||||
this.scope = this;
|
||||
|
||||
/**
|
||||
* The WebGL UV data cache.
|
||||
*
|
||||
|
@ -121,8 +113,7 @@ PIXI.Texture = function(baseTexture, frame)
|
|||
}
|
||||
else
|
||||
{
|
||||
var scope = this;
|
||||
baseTexture.addEventListener('loaded', function(){ scope.onBaseTextureLoaded(); });
|
||||
baseTexture.addEventListener('loaded', this.onBaseTextureLoaded.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -144,7 +135,7 @@ PIXI.Texture.prototype.onBaseTextureLoaded = function()
|
|||
|
||||
this.setFrame(this.frame);
|
||||
|
||||
this.scope.dispatchEvent( { type: 'update', content: this } );
|
||||
this.dispatchEvent( { type: 'update', content: this } );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,9 +13,10 @@
|
|||
* @param [view] {Canvas} the canvas to use as a view, optional
|
||||
* @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 [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(!height)height = 600;
|
||||
|
@ -31,7 +32,7 @@ PIXI.autoDetectRenderer = function(width, height, view, transparent, antialias)
|
|||
|
||||
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);
|
||||
|
@ -49,9 +50,10 @@ PIXI.autoDetectRenderer = function(width, height, view, transparent, antialias)
|
|||
* @param [view] {Canvas} the canvas to use as a view, optional
|
||||
* @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 [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(!height)height = 600;
|
||||
|
@ -69,7 +71,7 @@ PIXI.autoDetectRecommendedRenderer = function(width, height, view, transparent,
|
|||
|
||||
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);
|
||||
|
|
|
@ -21,15 +21,16 @@
|
|||
*
|
||||
* @method cancelAnimationFrame
|
||||
*/
|
||||
var lastTime = 0;
|
||||
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
||||
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
||||
(function(window) {
|
||||
var lastTime = 0;
|
||||
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
||||
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
||||
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
||||
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||
|
||||
window[vendors[x] + 'CancelRequestAnimationFrame'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!window.requestAnimationFrame) {
|
||||
if (!window.requestAnimationFrame) {
|
||||
window.requestAnimationFrame = function(callback) {
|
||||
var currTime = new Date().getTime();
|
||||
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
||||
|
@ -38,15 +39,16 @@ if (!window.requestAnimationFrame) {
|
|||
lastTime = currTime + timeToCall;
|
||||
return id;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (!window.cancelAnimationFrame) {
|
||||
if (!window.cancelAnimationFrame) {
|
||||
window.cancelAnimationFrame = function(id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
window.requestAnimFrame = window.requestAnimationFrame;
|
||||
window.requestAnimFrame = window.requestAnimationFrame;
|
||||
})(this);
|
||||
|
||||
/**
|
||||
* 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') {
|
||||
Function.prototype.bind = (function () {
|
||||
var slice = Array.prototype.slice;
|
||||
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();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -164,6 +172,7 @@ PIXI.unpackColorRGB = function(r, g, b)//r, g, b, a)
|
|||
*/
|
||||
PIXI.canUseNewCanvasBlendModes = function()
|
||||
{
|
||||
if (typeof document === 'undefined') return false;
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = 1;
|
||||
canvas.height = 1;
|
||||
|
|
Loading…
Reference in a new issue