Pixi.js: Not possible to move with interactive objects ( while function contains stopPropagation() )

Created on 4 Sep 2019  路  13Comments  路  Source: pixijs/pixi.js

Expected Behavior

Event pointermove correctly fired on all interactive objects even when function contains event.stopPropagation().

Current Behavior

I added two interactive sprites included their interactive functions pointerdown, pointermove, pointerup and pointerupoutside. In each of interactive function I fire event.stopPropagation().

In this use case is pointermove fired only at last sprite.

Check example: https://www.pixiplayground.com/#/edit/m0MxjDUGhTiZ5KU5aRO2C
( you should try move with both sprites, one is not working for me )

Environment

Most helpful comment

This is more fun with event re-use.

The reason it's "weird" here is pretty much because this line is "missing":

app.renderer.plugins.interaction.moveWhenInside = true;

Because of that both bunnies get the mousemove event, but the first bunny event listener stops the propagation of it, so it can't really reach the second bunny.

Now don't go adding that line just yet, because with it it's easy to "lose" a bunny while dragging (feel free to try this to find out what I'm talking about.)

Instead only use .stopPropagation when you actually "consumed" the event:

function pointermove(e) {
    console.log(`[${this.name}] [${e.type}] [dragging=${this.dragging}]`)
    if (this.dragging) {
        e.stopPropagation();
        // ...
    }
}

To really "fix" all this weirdness, InteractionManager would need to stop re-using events like that and also set:

app.renderer.plugins.interaction.moveWhenInside = true;

by default. Because not only is that a performance killer, (we're dispatching move events to everything), it's also confusing as hell. On top of that maybe provide a guide on how to do dragging properly: which is to listen to move events on a parent container, not the thing itself.

All 13 comments

https://github.com/pixijs/pixi.js/pull/6043 should have fixed this

Here's the playground using the latest dev version of the code
https://www.pixiplayground.com/#/edit/DeTY1ujsy3MlW6VkC8HUX

Okay nice, thanks, but it's not working for me. Is that dev link correct?

pixi

Should be. If it's still not working... @laino could you help here please?

This commit in 5.1.3 milestone and in master branch.
Build it.

So, last master build:
https://pixijs.download/fix-sprite-uv/pixi.js
And fiddle works:
https://www.pixiplayground.com/#/edit/NrbRAqII~OLns9HiGzoxK

But @themoonrat fiddle works too.

This is more fun with event re-use.

The reason it's "weird" here is pretty much because this line is "missing":

app.renderer.plugins.interaction.moveWhenInside = true;

Because of that both bunnies get the mousemove event, but the first bunny event listener stops the propagation of it, so it can't really reach the second bunny.

Now don't go adding that line just yet, because with it it's easy to "lose" a bunny while dragging (feel free to try this to find out what I'm talking about.)

Instead only use .stopPropagation when you actually "consumed" the event:

function pointermove(e) {
    console.log(`[${this.name}] [${e.type}] [dragging=${this.dragging}]`)
    if (this.dragging) {
        e.stopPropagation();
        // ...
    }
}

To really "fix" all this weirdness, InteractionManager would need to stop re-using events like that and also set:

app.renderer.plugins.interaction.moveWhenInside = true;

by default. Because not only is that a performance killer, (we're dispatching move events to everything), it's also confusing as hell. On top of that maybe provide a guide on how to do dragging properly: which is to listen to move events on a parent container, not the thing itself.

And of course, according to @laino , handling move event on moved element is not a good idea.

And of course, according to @laino , handling move event on moved element is not a good idea.

Well... it works right now. But just because moveWhenInside is false by default. But the documentation of it says:

It is currently set to false as this is how PixiJS used to work. This will be set to true in future versions of pixi.

So when that actually happens, all code listening to move events on the dragged element will break.

@eXponenta I accidentally edited @themoonrat's fiddle. I didn't realize it would overwrite other people's fiddles like that. I changed it back to be "broken" again.

Instead here's a fiddle with my suggested quick fix (still not "proper" dragging):

https://www.pixiplayground.com/#/edit/gDzO69len~gHz~Qsvi60u

And here's one with moveWhenInside = true:

https://www.pixiplayground.com/#/edit/ebDi62qprcKIsI9yiVNsD

@laino I rewrited @themoonrat 's fiddle too. Sometimes i forgets clone it. It's time to fix the playground.I created issues about auto clone: https://github.com/englercj/playground/issues/10

@laino okay thanks for explanation. I relied on documentation.

stopPropagation ()
Prevents event from reaching any objects other than the current object.

I just cant figure out how can it work :). InteractionManager still need to process all interactive objects to control if they have been hit. So why stopPropagation() cause that it is fired only at last object, please ?

The problem is that its two different types of behaviour, BROADCAST vs SINGLE EVENT.

I dont know how stopPropagation works on broadcasts in Flash.

Okay, thanks. I think it couldn't be changed now.
CLOSE

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaccob picture gaccob  路  3Comments

st3v0 picture st3v0  路  3Comments

YuryKuvetski picture YuryKuvetski  路  3Comments

courtneyvigo picture courtneyvigo  路  3Comments

finscn picture finscn  路  3Comments