Jump to content

[SOLVED] Sprite bounds do not update if sprite is invisible


Recommended Posts

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() {

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


  • Recently Browsing   0 members

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