Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A nifty little bug with sprite scaled to 0 & mouse clicks #602

Closed
georgiee opened this issue Mar 18, 2014 · 5 comments
Closed

A nifty little bug with sprite scaled to 0 & mouse clicks #602

georgiee opened this issue Mar 18, 2014 · 5 comments

Comments

@georgiee
Copy link
Contributor

Try the following code. A sprite scaled to zero catches all clicks. You even get a hand cursor on the whole stage. Phaser or Pixi Bug ?

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, render: render });

function preload() {
    game.load.image('bunny', 'assets/sprites/bunny.png');
}

var b;

function create() {
    b = game.add.sprite(game.world.centerX, game.world.centerY, 'bunny');
    b.anchor.setTo(0.5, 0.5);

    b.inputEnabled = true;
    b.input.useHandCursor = true;
    //b.scale.set(0.01) //works fine
    b.scale.set(0)
    b.events.onInputDown.add(clickSprite, this);
}

function clickSprite() {
    console.log('clickSprite');
}
function render() {

    game.debug.spriteInputInfo(b, 32, 32);
    game.debug.spriteCorners(b);
    game.debug.point(b.input._tempPoint);

}
@georgiee
Copy link
Contributor Author

By the way, another cosmetic bug with the hand cursor in this example.

When you try the example with a scale of 0.01 you can see the bunny as a tiny dot.
The hand cursor detection doesn't detect the shape right in this scale. So it happens that when you hover some times over the tiny bunny you will be left with a hand cursor even that you are not over the bunny anymore.

@georgiee
Copy link
Contributor Author

And for the records:
If you have the hand cursor enabled and you destroy the sprite by clicking on it you can't get rid of the hand cursor anymore- well you can but only by hovering over another sprite with an enabled hand cursor.

You should clear the hand cursor style when the sprite gets destroyed & the last reported state was over. A very dirty workaround is clearing the hand cursor yourself just before you destroy the sprite.

game.canvas.style.cursor = 'default'

photonstorm added a commit that referenced this issue Mar 19, 2014
…er-rode, renamed to World.shutdown and updated StateManager accordingly.

World.shutdown now removes all children iteratively, calling destroy on each one, ultimately performing a soft reset of the World.
Objects with a scale.x or y of 0 are no longer considered valid for input (fix #602)
InputHandler will set the browser pointer back to default if destroyed while over (fix #602)
Group.destroy has a new parameter: `soft`. A soft destruction won't remove the Group from its parent or null game references. Default is `false`.
InputHandler.validForInput is a new method that checks if the handler and its owner should be considered for Pointer input handling or not.
Group.replace will now return the old child, the one that was replaced in the Group.
@photonstorm
Copy link
Collaborator

Well there's a condition I didn't consider before :) (scale zero). Have modified how the input check is done, should be tighter now. Same goes for the hand cursor.

@photonstorm
Copy link
Collaborator

Pretty sure this is fixed, but please test and let me know.

@georgiee
Copy link
Contributor Author

Yes Rich. Everything is fixed! Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants