Graphics shape returning incorrect width/height values while tweening #2573

Closed
kelu-smiley opened this Issue Jun 18, 2016 · 4 comments

Projects

None yet

2 participants

@kelu-smiley

I've checked this with 2.5 and it's still present.

You can reproduce the bug with this code :

function bugTest()
    {
        var duration = 1000
        var interval = 200
        var blastRing = game.add.graphics(100,100)
        blastRing.lineStyle(2, 0xff0000, 1);
        blastRing.drawCircle(0, 0, 100);
        //console.log(blastRing.width + " : " + blastRing.height)
        blastRing.scale.setTo(0,0)

        var scaleTween = game.add.tween(blastRing.scale).to({x:1,y:1},duration, Phaser.Easing.Linear.None, true)
        game.time.events.repeat(interval, duration / interval, blastRingCheck, this, blastRing)
    }

    function blastRingCheck(blastRing)
    {
        console.log(blastRing.width + " : " + blastRing.height)
    }

Executing this code will log out what incorrect width/height values for the blastRing. The values 0-1 decimal values that seem to be the scale.x/scale.y values.

If you uncomment the console.log line in bugTest, the width/height values will log out correctly.

@photonstorm
Owner
photonstorm commented Jun 20, 2016 edited

There's something wrong here, but it's nothing to do with tweens. Graphics objects simply don't return the correct width and height, at all, if you adjust their scale without first calling getLocalBounds.

@kelu-smiley

Makes sense. So by logging out width/height, getLocalBounds was being called internally?

@photonstorm
Owner

Yes, exactly that.

@photonstorm photonstorm added a commit that referenced this issue Jun 29, 2016
@photonstorm All Pixi.Graphics methods that change the Graphics, i.e. `drawShape`,…
… `lineTo`, `arc`, etc will now all automatically call `Graphics.updateLocalBounds`. This is so that the bounds of the Graphics object are kept updated, allowing you to scale and rotate the Graphics object and still obtain correct dimensions from it (thanks @kelu-smiley #2573)
4066a8d
@photonstorm
Owner

Thanks for submitting this issue. We have fixed this, and the fix has been pushed to the dev branch.

@photonstorm photonstorm added a commit that referenced this issue Jul 23, 2016
@photonstorm As a result of changes in #2573 Graphics objects were calling `update…
…LocalBounds` on any shape change, which could cause dramatic performances drops in Graphics heavy situations (#2618). Graphics objects now have a new flag `_boundsDirty` which is used to detect if the bounds have been invalidated, i.e. by a Graphics being cleared or drawn to. If this is set to true then `updateLocalBounds` is called once in the `postUpdate` method (thanks @pengchuan #2618)
ce764e0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment