lgibson02 Posted February 18, 2018 Share Posted February 18, 2018 Hi, I was working on a project when I discovered that the boundaries of a sprite obtained with sprite.getBounds() seem to stop updating if sprite.visible is set to false. I know Phaser is meant to stop rendering sprites when a sprite is invisible but surely it should still update things like this. Is this intentional behavior or is it a bug? Here's some code and a webpage if you don't understand what I mean: var game = new Phaser.Game(512, 512, Phaser.AUTO, "", {preload: preload, create: create, update: update, render: render}); var test; var key; function preload() { game.load.image("test"); } function create() { test = game.add.sprite(0, 0, "test"); key = game.input.keyboard.addKey(Phaser.Keyboard.V); key.onDown.add(toggleVisibility, this); } function update() { test.x = game.input.mousePointer.x; test.y = game.input.mousePointer.y; } function toggleVisibility() { test.visible = !test.visible; } function render() { var b = test.getBounds(); game.debug.text("Bounds = x:" + b.x + " y:" + b.y + " w:" + b.width + " h:" + b.height, 0, 16); game.debug.text("Position = x:" + test.x + " y:" + test.y, 0, 32); } A link to this code working is here, it's on a home server so it may go down. Web server is now offline since problem is solved. Press V key to toggle visiblity of sprite. Notice when invisible sprite bounds stop updating but position still follows mouse. Link to comment Share on other sites More sharing options...
samme Posted February 19, 2018 Share Posted February 19, 2018 This is intentional, although surprising. You can use sprite.renderable = false or sprite.alpha = 0 Link to comment Share on other sites More sharing options...
lgibson02 Posted February 19, 2018 Author Share Posted February 19, 2018 32 minutes ago, samme said: This is intentional, although surprising. You can use sprite.renderable = false or sprite.alpha = 0 Yes that worked, thank you very much. Link to comment Share on other sites More sharing options...
Recommended Posts