Input Event Handling cannot be stopped from bubbling #3249
-
Hello! I've been trying out excalibur.js a little over last few days, but hit a problem with event handlers I couldn't figure out using the docs and github issues. I implemented drag&drop panning in the scene (think grand strategy game), using https://excaliburjs.com/docs/pointers/#event-handlers. In that scene I render an actor that has a click handler Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi @johannes-z! Good question! Can you post a code example as well? Unfortunately using the I think you might be right, I'm looking at the pointer system source code and it is possible to do One workaround might be to manually inspect whether the event has been canceled? It is my thought this should ultimately happen automatically... actor.on('pointerdown', (pe: ex.PointerEvent) => {
console.log('select actor');
pe.cancel(); // cancel the event
});
game.input.pointers.primary.on('down', (e) => {
if (!e.active) {
console.log('canceled', e);
}
}); |
Beta Was this translation helpful? Give feedback.
-
Yes this seems to work. I didn't post any code cause it doesn't really exceed what's in the docs, but for completeness sake I'll post what I have. calling import { Color, DisplayMode, Engine, PointerScope, Actor, Circle, vec } from 'excalibur'
export class Star extends Actor {
constructor(config?: ActorArgs) {
super({
z: 100,
...config,
})
this.graphics.use(new Circle({
radius: 10,
color: Color.Yellow,
}))
this.pointer.useGraphicsBounds = true
this.on('pointerdown', (evt) => {
console.log('Clicked!')
console.log(evt)
evt.cancel()
})
return this
}
}
const game = new Engine({
canvasElementId: 'game',
displayMode: DisplayMode.FillContainer,
backgroundColor: Color.Black,
pointerScope: PointerScope.Document,
})
game.input.pointers.on('down', async (evt) => {
console.log('down')
console.log(evt.active)
console.log(evt)
})
const star = new Star({
pos: vec(100, 0),
})
game.add(star)
game.start() |
Beta Was this translation helpful? Give feedback.
-
@johannes-z PR merged! should be deployed in the alpha bits soon |
Beta Was this translation helpful? Give feedback.
Awesome, this should be an easy bugfix if I'm reading the excalibur code right. I've made an issue! #3250