Experimenting with generateTexture fixes for Canvas.

This commit is contained in:
photonstorm 2015-07-30 17:17:27 +01:00
parent 0bad5e4ab2
commit 159f49d5bf
2 changed files with 57 additions and 9 deletions

View file

@ -263,6 +263,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
* Pointer.isDown was reset before the Input.onUp event, meaning you couldn't get the Pointer.duration from within the event.
* Pointer.isDown was reset before the Input tap calculations, meaning onTap wouldn't dispatch (thanks @stovenator #1953)
* InputHandler.pointerOver would get stuck in an 'isOver' state if the Sprite changed its visibility during an onUp callback (thanks @Cristy94 #1955)
* If you override the P2 mpx functions, to define your own px to meters values, the P2 Debug Bodies would ignore it (thanks @vrecluse #1957)
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).

View file

@ -382,10 +382,12 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', {
if (value)
{
console.log('DisplayObject.cacheAsBitmap - gen');
this._generateCachedSprite();
}
else
{
console.log('DisplayObject.cacheAsBitmap - nuke');
this._destroyCachedSprite();
}
@ -648,31 +650,76 @@ PIXI.DisplayObject.prototype._generateCachedSprite = function()
var bounds = this.getLocalBounds();
this.updateTransform();
console.log('bounds', bounds);
if (!this._cachedSprite)
{
var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer);
var renderTexture = new PIXI.RenderTexture(bounds.width | 1, bounds.height | 1);
this._cachedSprite = new PIXI.Sprite(renderTexture);
this._cachedSprite.worldTransform = this.worldTransform;
}
else
{
this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0);
this._cachedSprite.texture.resize(bounds.width | 1, bounds.height | 1);
}
//REMOVE filter!
// Remove filters
var tempFilters = this._filters;
this._filters = null;
this._cachedSprite.filters = tempFilters;
PIXI.DisplayObject._tempMatrix.identity();
PIXI.DisplayObject._tempMatrix.tx = -bounds.x;
PIXI.DisplayObject._tempMatrix.ty = -bounds.y;
this._cachedSprite.texture.render(this, PIXI.DisplayObject._tempMatrix, true);
this._cachedSprite.anchor.x = -( bounds.x / bounds.width );
this._cachedSprite.anchor.y = -( bounds.y / bounds.height );
console.log(PIXI.DisplayObject._tempMatrix);
// if (matrix === undefined || matrix === null)
// {
// var m = new Phaser.Matrix();
// m.scale(1, -1);
// m.tx = -bounds.x;
// m.ty = -bounds.y;
// m.copyFrom(this.worldTransform);
// this._tempMatrix.copyFrom(displayObject.worldTransform);
// }
// else
// {
// this._tempMatrix.copyFrom(matrix);
// }
// Let's create a nice matrix to apply to our display object.
// Frame buffers come in upside down so we need to flip the matrix.
// var wt = this.worldTransform;
// wt.identity();
// wt.translate(0, this.projection.y * 2);
// if (matrix)
// {
// wt.append(matrix);
// }
// wt.scale(1, -1);
this._cachedSprite.texture.textureBuffer.context.fillStyle = 'rgba(255,0,0,0.2)';
this._cachedSprite.texture.textureBuffer.context.fillRect(0, 0, this._cachedSprite.texture.textureBuffer.canvas.width, this._cachedSprite.texture.textureBuffer.canvas.height);
// this._cachedSprite.texture.render(this, m, true);
this._cachedSprite.texture.render(this, PIXI.DisplayObject._tempMatrix, false);
// console.log(m);
// this._cachedSprite.texture.render(this, PIXI.DisplayObject._tempMatrix, true);
// this._cachedSprite.anchor.x = -( bounds.x / bounds.width );
// this._cachedSprite.anchor.y = -( bounds.y / bounds.height );
console.log(this._cachedSprite.position);
this._filters = tempFilters;