Jump to content

group.getBounds() different results


osinski
 Share

Recommended Posts

Hi!

Could you explain why bounds are different after timeout?

function create() {

    var sprite = game.add.sprite(0, 0, 'phaser');
    var group = game.add.group();
    group.add(sprite);
    group.x = 200;
    group.y = 200;
    
    console.log(group.getBounds());///c.Rectangle {x: 0, y: 0, width: 27, height: 40, type: 22}
    setTimeout(()=>{console.log(group.getBounds());}, 1);///c.Rectangle {x: 200, y: 200, width: 27, height: 40, type: 22}

}

 

Link to comment
Share on other sites

Because Pixi uses a deferred transform update. Your timeout allows for a render pass to have occurred, thus updating the transforms in the process.

Instead of using setTimeout, just put in 'game.stage.updateTransform()', and it'll reflow all of the transforms, giving the same result.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...