lgibson02

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.