mirror of
https://github.com/wassname/phaser.git
synced 2026-08-15 12:45:11 +08:00
Updated to latest pixi and p2.js
This commit is contained in:
@@ -204,7 +204,7 @@ PIXI.InteractionManager.prototype.setTargetDomElement = function(domElement)
|
||||
domElement.addEventListener('touchend', this.onTouchEnd, true);
|
||||
domElement.addEventListener('touchmove', this.onTouchMove, true);
|
||||
|
||||
document.body.addEventListener('mouseup', this.onMouseUp, true);
|
||||
window.addEventListener('mouseup', this.onMouseUp, true);
|
||||
};
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ PIXI.InteractionManager.prototype.removeEvents = function()
|
||||
|
||||
this.interactionDOMElement = null;
|
||||
|
||||
document.body.removeEventListener('mouseup', this.onMouseUp, true);
|
||||
window.removeEventListener('mouseup', this.onMouseUp, true);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -99,20 +99,12 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
||||
var context = renderSession.context;
|
||||
context.globalAlpha = this.worldAlpha;
|
||||
|
||||
var transform = this.worldTransform;
|
||||
PIXI.DisplayObject.prototype.updateTransform.call(this);
|
||||
|
||||
var transform = this.worldTransform;
|
||||
// alow for trimming
|
||||
|
||||
if (renderSession.roundPixels)
|
||||
{
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, Math.floor(transform.tx), Math.floor(transform.ty));
|
||||
}
|
||||
else
|
||||
{
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
|
||||
}
|
||||
|
||||
context.save();
|
||||
var isRotated = true;
|
||||
|
||||
for (var i = 0; i < this.children.length; i++) {
|
||||
|
||||
@@ -124,8 +116,13 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
||||
|
||||
if(child.rotation % (Math.PI * 2) === 0)
|
||||
{
|
||||
|
||||
// this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call
|
||||
if(isRotated)
|
||||
{
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
|
||||
isRotated = false;
|
||||
}
|
||||
|
||||
// this is the fastest way to optimise! - if rotation is 0 then we can avoid any kind of setTransform call
|
||||
context.drawImage(texture.baseTexture.source,
|
||||
frame.x,
|
||||
frame.y,
|
||||
@@ -138,24 +135,23 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!isRotated)isRotated = true;
|
||||
|
||||
PIXI.DisplayObject.prototype.updateTransform.call(child);
|
||||
|
||||
transform = child.localTransform;
|
||||
var childTransform = child.worldTransform;
|
||||
|
||||
if(this.rotation !== this.rotationCache)
|
||||
// allow for trimming
|
||||
|
||||
if (renderSession.roundPixels)
|
||||
{
|
||||
this.rotationCache = this.rotation;
|
||||
this._sr = Math.sin(this.rotation);
|
||||
this._cr = Math.cos(this.rotation);
|
||||
context.setTransform(childTransform.a, childTransform.c, childTransform.b, childTransform.d, childTransform.tx || 0, childTransform.ty || 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.setTransform(childTransform.a, childTransform.c, childTransform.b, childTransform.d, childTransform.tx, childTransform.ty);
|
||||
}
|
||||
|
||||
var a = child._cr * child.scale.x,
|
||||
b = -child._sr * child.scale.y,
|
||||
c = child._sr * child.scale.x,
|
||||
d = child._cr * child.scale.y;
|
||||
|
||||
context.setTransform(a, c, b, d, child.position.x, child.position.y);
|
||||
|
||||
context.drawImage(texture.baseTexture.source,
|
||||
frame.x,
|
||||
frame.y,
|
||||
@@ -165,10 +161,13 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
||||
((child.anchor.y) * (-frame.height) + 0.5) | 0,
|
||||
frame.width,
|
||||
frame.height);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// context.restore();
|
||||
}
|
||||
|
||||
context.restore();
|
||||
// context.restore();
|
||||
};
|
||||
|
||||
|
||||
@@ -132,6 +132,36 @@ PIXI.TilingSprite.prototype.onTextureUpdate = function()
|
||||
this.updateFrame = true;
|
||||
};
|
||||
|
||||
PIXI.TilingSprite.prototype.setTexture = function(texture)
|
||||
{
|
||||
if(this.texture === texture)return;
|
||||
|
||||
this.texture = texture;
|
||||
|
||||
this.refreshTexture = true;
|
||||
/*
|
||||
if(this.tilingTexture)
|
||||
{
|
||||
this.generateTilingTexture(true);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// stop current texture;
|
||||
if(this.texture.baseTexture !== texture.baseTexture)
|
||||
{
|
||||
this.textureChange = true;
|
||||
this.texture = texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
this.updateFrame = true;*/
|
||||
this.cachedTint = 0xFFFFFF;
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders the object using the WebGL renderer
|
||||
*
|
||||
@@ -161,7 +191,7 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
||||
renderSession.filterManager.pushFilter(this._filterBlock);
|
||||
}
|
||||
|
||||
if(!this.tilingTexture)this.generateTilingTexture(true);
|
||||
if(!this.tilingTexture || this.refreshTexture)this.generateTilingTexture(true);
|
||||
else renderSession.spriteBatch.renderTilingSprite(this);
|
||||
|
||||
// simple render children!
|
||||
@@ -179,7 +209,17 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!this.tilingTexture)this.generateTilingTexture(true);
|
||||
if(!this.tilingTexture || this.refreshTexture)
|
||||
{
|
||||
this.generateTilingTexture(true);
|
||||
if(this.tilingTexture.needsUpdate)
|
||||
{
|
||||
//TODO - tweaking
|
||||
PIXI.updateWebGLTexture(this.tilingTexture.baseTexture, renderSession.gl);
|
||||
this.tilingTexture.needsUpdate = false;
|
||||
// this.tilingTexture._uvs = null;
|
||||
}
|
||||
}
|
||||
else renderSession.spriteBatch.renderTilingSprite(this);
|
||||
|
||||
// simple render children!
|
||||
@@ -218,10 +258,10 @@ PIXI.TilingSprite.prototype._renderCanvas = function(renderSession)
|
||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);
|
||||
|
||||
|
||||
if(!this.__tilePattern)
|
||||
if(!this.__tilePattern || this.refreshTexture)
|
||||
{
|
||||
this.generateTilingTexture(false);
|
||||
|
||||
|
||||
if(this.tilingTexture)
|
||||
{
|
||||
this.__tilePattern = context.createPattern(this.tilingTexture.baseTexture.source, 'repeat');
|
||||
@@ -360,59 +400,78 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
|
||||
var targetWidth, targetHeight;
|
||||
|
||||
// check that the frame is the same size as the base texture.
|
||||
|
||||
var isFrame = frame.width !== baseTexture.width || frame.height !== baseTexture.height;
|
||||
|
||||
this.tilingTexture = texture;
|
||||
|
||||
var newTextureRequired = false;
|
||||
|
||||
if(!forcePowerOfTwo)
|
||||
{
|
||||
if(isFrame)
|
||||
{
|
||||
if (texture.trim)
|
||||
{
|
||||
targetWidth = texture.trim.width;
|
||||
targetHeight = texture.trim.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetWidth = frame.width;
|
||||
targetHeight = frame.height;
|
||||
}
|
||||
|
||||
targetWidth = frame.width;
|
||||
targetHeight = frame.height;
|
||||
|
||||
newTextureRequired = true;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
targetWidth = PIXI.getNextPowerOfTwo(texture.frame.width);
|
||||
targetHeight = PIXI.getNextPowerOfTwo(texture.frame.height);
|
||||
|
||||
targetWidth = PIXI.getNextPowerOfTwo(frame.width);
|
||||
targetHeight = PIXI.getNextPowerOfTwo(frame.height);
|
||||
if(frame.width !== targetWidth && frame.height !== targetHeight)newTextureRequired = true;
|
||||
}
|
||||
|
||||
if(newTextureRequired)
|
||||
{
|
||||
var canvasBuffer = new PIXI.CanvasBuffer(targetWidth, targetHeight);
|
||||
var canvasBuffer;
|
||||
|
||||
if(this.tilingTexture && this.tilingTexture.isTiling)
|
||||
{
|
||||
canvasBuffer = this.tilingTexture.canvasBuffer;
|
||||
canvasBuffer.resize(targetWidth, targetHeight);
|
||||
this.tilingTexture.baseTexture.width = targetWidth;
|
||||
this.tilingTexture.baseTexture.height = targetHeight;
|
||||
this.tilingTexture.needsUpdate = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
canvasBuffer = new PIXI.CanvasBuffer(targetWidth, targetHeight);
|
||||
|
||||
this.tilingTexture = PIXI.Texture.fromCanvas(canvasBuffer.canvas);
|
||||
this.tilingTexture.canvasBuffer = canvasBuffer;
|
||||
this.tilingTexture.isTiling = true;
|
||||
|
||||
}
|
||||
|
||||
canvasBuffer.context.drawImage(texture.baseTexture.source,
|
||||
frame.x,
|
||||
frame.y,
|
||||
frame.width,
|
||||
frame.height,
|
||||
0,
|
||||
0,
|
||||
targetWidth,
|
||||
targetHeight);
|
||||
|
||||
this.tilingTexture = PIXI.Texture.fromCanvas(canvasBuffer.canvas);
|
||||
frame.x,
|
||||
frame.y,
|
||||
frame.width,
|
||||
frame.height,
|
||||
0,
|
||||
0,
|
||||
targetWidth,
|
||||
targetHeight);
|
||||
|
||||
this.tileScaleOffset.x = frame.width / targetWidth;
|
||||
this.tileScaleOffset.y = frame.height / targetHeight;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO - switching?
|
||||
if(this.tilingTexture && this.tilingTexture.isTiling)
|
||||
{
|
||||
// destroy the tiling texture!
|
||||
// TODO could store this somewhere?
|
||||
this.tilingTexture.destroy(true);
|
||||
}
|
||||
|
||||
this.tileScaleOffset.x = 1;
|
||||
this.tileScaleOffset.y = 1;
|
||||
this.tilingTexture = texture;
|
||||
}
|
||||
this.refreshTexture = false;
|
||||
this.tilingTexture.baseTexture._powerOf2 = true;
|
||||
};
|
||||
@@ -277,11 +277,11 @@ PIXI.WebGLSpriteBatch.prototype.renderTilingSprite = function(tilingSprite)
|
||||
|
||||
var uvs = tilingSprite._uvs;
|
||||
|
||||
tilingSprite.tilePosition.x %= texture.baseTexture.width;
|
||||
tilingSprite.tilePosition.y %= texture.baseTexture.height;
|
||||
tilingSprite.tilePosition.x %= texture.baseTexture.width * tilingSprite.tileScaleOffset.x;
|
||||
tilingSprite.tilePosition.y %= texture.baseTexture.height * tilingSprite.tileScaleOffset.y;
|
||||
|
||||
var offsetX = tilingSprite.tilePosition.x/texture.baseTexture.width;
|
||||
var offsetY = tilingSprite.tilePosition.y/texture.baseTexture.height;
|
||||
var offsetX = tilingSprite.tilePosition.x/(texture.baseTexture.width*tilingSprite.tileScaleOffset.x);
|
||||
var offsetY = tilingSprite.tilePosition.y/(texture.baseTexture.height*tilingSprite.tileScaleOffset.y);
|
||||
|
||||
var scaleX = (tilingSprite.width / texture.baseTexture.width) / (tilingSprite.tileScale.x * tilingSprite.tileScaleOffset.x);
|
||||
var scaleY = (tilingSprite.height / texture.baseTexture.height) / (tilingSprite.tileScale.y * tilingSprite.tileScaleOffset.y);
|
||||
|
||||
@@ -56,6 +56,8 @@ PIXI.Texture = function(baseTexture, frame)
|
||||
|
||||
this.scope = this;
|
||||
|
||||
this._uvs = null;
|
||||
|
||||
if(baseTexture.hasLoaded)
|
||||
{
|
||||
if(this.noFrame)frame = new PIXI.Rectangle(0,0, baseTexture.width, baseTexture.height);
|
||||
|
||||
Reference in New Issue
Block a user