Skip to content
This repository has been archived by the owner on May 8, 2018. It is now read-only.

isoSprite _isoPositionChanged is broken #46

Open
stovenator opened this issue Aug 2, 2016 · 2 comments
Open

isoSprite _isoPositionChanged is broken #46

stovenator opened this issue Aug 2, 2016 · 2 comments
Assignees
Labels

Comments

@stovenator
Copy link

stovenator commented Aug 2, 2016

In the prototype for isoSprite , there's no way for _isoSpriteChanged to ever get set false, so every update cycle the it updates the isoSprite, regardless of need and has to re-do the math for resetBounds and depth.

Phaser.Plugin.Isometric.IsoSprite.prototype._project = function () {
    if (this._isoPositionChanged) {
        this.game.iso.project(this._isoPosition, this.position);

        if (this.snap > 0) {
            this.position.x = Phaser.Math.snapTo(this.position.x, this.snap);
            this.position.y = Phaser.Math.snapTo(this.position.y, this.snap);
        }

        this._depthChanged = this._isoPositionChanged = this._isoBoundsChanged = true;
    }
};

This can be changed to be:

    this._isoPositionChanged = false;
    this._depthChanged = this._isoBoundsChanged = true;

After this change, it requires that isoSprite positioning is changed only using isoSprite.isoX, isoSprite.isoY, and isoSprite.isoZ because those setters update the _isoPositionChanged flag, or with body.reset if there is a body.

If the position is updated using isoSprite.isoPosition.setTo(x,y,z) , _isoPositionChanged never gets set and thus the position.x, position.y remain unchanged.

@lewster32
Copy link
Owner

Nice spot - I'll take a look at this and see what I can do to maintain compatibility. This as you can probably tell is a caching technique to prevent unnecessary projection calculations but it looks like it's not doing its job!

@lewster32 lewster32 self-assigned this Aug 3, 2016
@lewster32 lewster32 added the bug label Aug 3, 2016
@stovenator
Copy link
Author

I also noticed that in the Body postUpdate, there's no dirty check. I adjusted it in mine to look like this, but likely it could be optimized more:

            if(this._dx !== 0 || this._dy !== 0 || this._dx !== 0){
                this.sprite.isoX += this._dx;
                this.sprite.isoY += this._dy;
                this.sprite.isoZ += this._dz;
            }

...

        if (this.position.x !== this.prev.x || this.position.y !== this.prev.y || this.position.z !== this.prev.z){
            this.prev.x = this.position.x;
            this.prev.y = this.position.y;
            this.prev.z = this.position.z;
        }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants