Skip to content

Commit 3ff8b9f

Browse files
committed
On-going crop tests.
1 parent f1bcd1d commit 3ff8b9f

1 file changed

Lines changed: 82 additions & 71 deletions

File tree

src/gameobjects/Sprite.js

Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -464,15 +464,17 @@ Phaser.Sprite.prototype.setFrame = function(frame) {
464464
}
465465
}
466466

467-
if (this.game.renderType === Phaser.WEBGL)
468-
{
469-
PIXI.WebGLRenderer.updateTextureFrame(this.texture);
470-
}
471-
472467
if (this.cropRect)
473468
{
474469
this.updateCrop();
475470
}
471+
else
472+
{
473+
if (this.game.renderType === Phaser.WEBGL)
474+
{
475+
PIXI.WebGLRenderer.updateTextureFrame(this.texture);
476+
}
477+
}
476478

477479
};
478480

@@ -483,6 +485,69 @@ Phaser.Sprite.prototype.setFrame = function(frame) {
483485
* @method Phaser.Sprite#updateCrop
484486
* @memberof Phaser.Sprite
485487
*/
488+
Phaser.Sprite.prototype.PREupdateCrop = function() {
489+
490+
if (!this.cropRect)
491+
{
492+
return;
493+
}
494+
495+
if (this.texture.trim)
496+
{
497+
this._cache[15] = this._cache[9] + this.cropRect.x - this._cache[13];
498+
499+
if (this._cache[15] < this._cache[9])
500+
{
501+
this._cache[15] = this._cache[9];
502+
}
503+
504+
this._cache[16] = this._cache[10] + this.cropRect.y - this._cache[14];
505+
506+
if (this._cache[16] < this._cache[10])
507+
{
508+
this._cache[16] = this._cache[10];
509+
}
510+
511+
this.texture.frame.x = this._cache[15];
512+
this.texture.frame.y = this._cache[16];
513+
514+
this._cache[15] = 0;
515+
this._cache[16] = 0;
516+
517+
if (this.cropRect.x === 0)
518+
{
519+
this._cache[15] = this._cache[13];
520+
}
521+
522+
if (this.cropRect.y === 0)
523+
{
524+
this._cache[16] = this._cache[14];
525+
}
526+
527+
this.texture.frame.width = this.cropRect.width - this._cache[15];
528+
this.texture.frame.height = this.cropRect.height - this._cache[16];
529+
530+
this.texture.trim.x = this._cache[15];
531+
this.texture.trim.y = this._cache[16];
532+
this.texture.trim.width = this.cropRect.width;
533+
this.texture.trim.height = this.cropRect.height;
534+
}
535+
else
536+
{
537+
this.texture.frame.x = this._cache[9] + this.cropRect.x;
538+
this.texture.frame.y = this._cache[10] + this.cropRect.y;
539+
this.texture.frame.width = this.cropRect.width;
540+
this.texture.frame.height = this.cropRect.height;
541+
}
542+
543+
if (this.game.renderType === Phaser.WEBGL)
544+
{
545+
PIXI.WebGLRenderer.updateTextureFrame(this.texture);
546+
}
547+
548+
};
549+
550+
486551
Phaser.Sprite.prototype.updateCrop = function() {
487552

488553
if (!this.cropRect)
@@ -493,7 +558,7 @@ Phaser.Sprite.prototype.updateCrop = function() {
493558
if (this.texture.trim)
494559
{
495560
/*
496-
var frame = this.texture.frame;
561+
var frame = this.texture.frame;
497562
498563
var trim = texture.trim;
499564
@@ -550,10 +615,18 @@ Phaser.Sprite.prototype.updateCrop = function() {
550615
551616
worldTransform uses texture.frame.width / height to work out offset from x/y
552617
618+
this._cache[9] = frame.x;
619+
this._cache[10] = frame.y;
620+
this._cache[11] = frame.width;
621+
this._cache[12] = frame.height;
622+
this._cache[13] = frame.spriteSourceSizeX;
623+
this._cache[14] = frame.spriteSourceSizeY;
624+
this._cache[15] = trim calc x
625+
this._cache[16] = trim calc y
626+
this._cache[17] = frame.sourceSizeW;
627+
this._cache[18] = frame.sourceSizeH;
553628
*/
554629

555-
//
556-
557630
var tx = this._cache[9] - this._cache[13];
558631
var ty = this._cache[10] - this._cache[14];
559632

@@ -573,69 +646,6 @@ Phaser.Sprite.prototype.updateCrop = function() {
573646

574647
// But we still need to adjust the trim values
575648

576-
577-
578-
// this.texture.frame.x = this._cache[9] + this.cropRect.x;
579-
// this.texture.frame.y = this._cache[10] + this.cropRect.y;
580-
// this.texture.frame.width = this.cropRect.width;
581-
// this.texture.frame.height = this.cropRect.height;
582-
583-
// this.texture.trim.width = this.cropRect.width;
584-
// this.texture.trim.height = this.cropRect.height;
585-
586-
587-
// this._cache[9] = frame.x;
588-
// this._cache[10] = frame.y;
589-
// this._cache[11] = frame.width;
590-
// this._cache[12] = frame.height;
591-
// this._cache[13] = frame.spriteSourceSizeX;
592-
// this._cache[14] = frame.spriteSourceSizeY;
593-
// this._cache[15] = trim calc x
594-
// this._cache[16] = trim calc y
595-
// this._cache[17] = frame.sourceSizeW;
596-
// this._cache[18] = frame.sourceSizeH;
597-
598-
599-
/*
600-
this._cache[15] = this._cache[9] + this.cropRect.x - this._cache[13];
601-
602-
if (this._cache[15] < this._cache[9])
603-
{
604-
this._cache[15] = this._cache[9];
605-
}
606-
607-
this._cache[16] = this._cache[10] + this.cropRect.y - this._cache[14];
608-
609-
if (this._cache[16] < this._cache[10])
610-
{
611-
this._cache[16] = this._cache[10];
612-
}
613-
614-
this.texture.frame.x = this._cache[15];
615-
this.texture.frame.y = this._cache[16];
616-
617-
this._cache[15] = 0;
618-
this._cache[16] = 0;
619-
620-
if (this.cropRect.x === 0)
621-
{
622-
this._cache[15] = this._cache[13];
623-
}
624-
625-
if (this.cropRect.y === 0)
626-
{
627-
this._cache[16] = this._cache[14];
628-
}
629-
630-
this.texture.frame.width = this.cropRect.width - this._cache[15];
631-
this.texture.frame.height = this.cropRect.height - this._cache[16];
632-
633-
this.texture.trim.x = this._cache[13];
634-
this.texture.trim.y = this._cache[14];
635-
// Double-check we need this
636-
this.texture.trim.width = this.cropRect.width;
637-
this.texture.trim.height = this.cropRect.height;
638-
*/
639649
}
640650
else
641651
{
@@ -645,6 +655,7 @@ Phaser.Sprite.prototype.updateCrop = function() {
645655
this.texture.frame.height = this.cropRect.height;
646656
}
647657

658+
648659
if (this.game.renderType === Phaser.WEBGL)
649660
{
650661
PIXI.WebGLRenderer.updateTextureFrame(this.texture);

0 commit comments

Comments
 (0)