Skip to content

Commit 159f49d

Browse files
committed
Experimenting with generateTexture fixes for Canvas.
1 parent 0bad5e4 commit 159f49d

2 files changed

Lines changed: 57 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
263263
* Pointer.isDown was reset before the Input.onUp event, meaning you couldn't get the Pointer.duration from within the event.
264264
* Pointer.isDown was reset before the Input tap calculations, meaning onTap wouldn't dispatch (thanks @stovenator #1953)
265265
* InputHandler.pointerOver would get stuck in an 'isOver' state if the Sprite changed its visibility during an onUp callback (thanks @Cristy94 #1955)
266+
* 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)
266267

267268
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
268269

src/pixi/display/DisplayObject.js

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,12 @@ Object.defineProperty(PIXI.DisplayObject.prototype, 'cacheAsBitmap', {
382382

383383
if (value)
384384
{
385+
console.log('DisplayObject.cacheAsBitmap - gen');
385386
this._generateCachedSprite();
386387
}
387388
else
388389
{
390+
console.log('DisplayObject.cacheAsBitmap - nuke');
389391
this._destroyCachedSprite();
390392
}
391393

@@ -648,31 +650,76 @@ PIXI.DisplayObject.prototype._generateCachedSprite = function()
648650

649651
var bounds = this.getLocalBounds();
650652

653+
this.updateTransform();
654+
655+
console.log('bounds', bounds);
656+
651657
if (!this._cachedSprite)
652658
{
653-
var renderTexture = new PIXI.RenderTexture(bounds.width | 0, bounds.height | 0);//, renderSession.renderer);
654-
659+
var renderTexture = new PIXI.RenderTexture(bounds.width | 1, bounds.height | 1);
655660
this._cachedSprite = new PIXI.Sprite(renderTexture);
656661
this._cachedSprite.worldTransform = this.worldTransform;
657662
}
658663
else
659664
{
660-
this._cachedSprite.texture.resize(bounds.width | 0, bounds.height | 0);
665+
this._cachedSprite.texture.resize(bounds.width | 1, bounds.height | 1);
661666
}
662667

663-
//REMOVE filter!
668+
// Remove filters
664669
var tempFilters = this._filters;
665670
this._filters = null;
666-
667671
this._cachedSprite.filters = tempFilters;
668672

673+
PIXI.DisplayObject._tempMatrix.identity();
669674
PIXI.DisplayObject._tempMatrix.tx = -bounds.x;
670675
PIXI.DisplayObject._tempMatrix.ty = -bounds.y;
671-
672-
this._cachedSprite.texture.render(this, PIXI.DisplayObject._tempMatrix, true);
673676

674-
this._cachedSprite.anchor.x = -( bounds.x / bounds.width );
675-
this._cachedSprite.anchor.y = -( bounds.y / bounds.height );
677+
console.log(PIXI.DisplayObject._tempMatrix);
678+
679+
// if (matrix === undefined || matrix === null)
680+
// {
681+
682+
// var m = new Phaser.Matrix();
683+
// m.scale(1, -1);
684+
// m.tx = -bounds.x;
685+
// m.ty = -bounds.y;
686+
687+
// m.copyFrom(this.worldTransform);
688+
689+
// this._tempMatrix.copyFrom(displayObject.worldTransform);
690+
// }
691+
// else
692+
// {
693+
// this._tempMatrix.copyFrom(matrix);
694+
// }
695+
696+
697+
// Let's create a nice matrix to apply to our display object.
698+
// Frame buffers come in upside down so we need to flip the matrix.
699+
// var wt = this.worldTransform;
700+
// wt.identity();
701+
// wt.translate(0, this.projection.y * 2);
702+
703+
// if (matrix)
704+
// {
705+
// wt.append(matrix);
706+
// }
707+
708+
// wt.scale(1, -1);
709+
710+
this._cachedSprite.texture.textureBuffer.context.fillStyle = 'rgba(255,0,0,0.2)';
711+
this._cachedSprite.texture.textureBuffer.context.fillRect(0, 0, this._cachedSprite.texture.textureBuffer.canvas.width, this._cachedSprite.texture.textureBuffer.canvas.height);
712+
713+
// this._cachedSprite.texture.render(this, m, true);
714+
this._cachedSprite.texture.render(this, PIXI.DisplayObject._tempMatrix, false);
715+
716+
// console.log(m);
717+
718+
// this._cachedSprite.texture.render(this, PIXI.DisplayObject._tempMatrix, true);
719+
// this._cachedSprite.anchor.x = -( bounds.x / bounds.width );
720+
// this._cachedSprite.anchor.y = -( bounds.y / bounds.height );
721+
722+
console.log(this._cachedSprite.position);
676723

677724
this._filters = tempFilters;
678725

0 commit comments

Comments
 (0)