kittykatattack / tink

A set of sprite interactivity tools for Pixi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple interactive sprites not changing mouse cursor appearance

dlmar10 opened this issue · comments

I have multiple sprites that I need to make interactive.

let t = new Tink(PIXI, renderer.view, scale);

let setup = () => {
    ...

    t.makeInteractive(spriteOne);
    t.makeInteractive(spriteTwo);
    t.makeInteractive(spriteThree);
    t.makeInteractive(spriteFour);

    pointer = t.makePointer();

    ...
}

However, when I do so, only the sprite that I most recently made interactive (spriteFour) will trigger the mouse pointer to change to the "pointer" style, signifying that the sprite is clickable. Hovering over spriteOne, spriteTwo, or spriteThree will not trigger a change in the mouse pointer's appearance.

sprite.press = () => {...} and sprite.over = () => {...} event functions will correctly trigger on all sprites, as I can log to the console, but the mouse pointer simply does not change style except over spriteFour. I have tried to overwrite the pointer style manually using if(pointer.hitTestSprite(sprite)){...} in the play function, but it has no effect.

I am using Pixi v4.3.1.

Hi, yes, this is a bug!
I encountered it on one of my own projects a few weeks ago.
I'll look into it.

This is because of the updateButtons() function. The forEach loops which go through all buttons and all pointers should be switched. As it is now, later buttons overwrite the pointer.cursor attribute for every pointer, which was set for earlier buttons (this is why the last button correctly sets the cursor to "pointer").

What's the build process here? I can fix this bug in src/tink.js, but I'm not sure how to re-build bin/tink.js to test this.

@andrewhalle Thanks so much for tracking this down, and I would love your help with this!
The source files are written in ES6 an then compiled down to ES5 using Babel, like this:

babel src/tink.js --out-file bin/tink.js --source-maps

Or, if you can post a fix to this bug in this Issue, I can do the new build.

@kittykatattack just submitted the PR!

@andrewhalle Thank you! We were actually working on this at exactly the same time 😄 But I've merged your changes and resolved the conflict and pushed a new build file. Looks good!

@kittykatattack No problem! This is a really great resource you've built, we use it to make menu buttons for our games.