Hi,
I’m getting Unable to preventDefault inside passive event listener invocation
error when clicking on the pause button.
PauseGame.prototype.pause = function(event){
event.event.preventDefault();
this.isPaused = true;
this.pausePopup.enabled = true;
this.entity.enabled = false;
this.app.timeScale = 0;
};
I’m using the preventDefault()
so that when I click the pause button, the ball doesn’t jump but it seems that does not work.
As you can see in the above picture when I click the pause button the ball jumps which I don’t need. Is there any way to prevent it?
Thank you
@yaustar I tried that also, but still, the ball jumps in the background. And yes its an PlayCanvas UI Element.
below is the code I added to button.
this.entity.element.on('click', this.pause, this);
This is the code for attaching events for jump on mouse events.
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
Project link: https://playcanvas.com/project/776440/overview/dunk-game-copy
Hi @maheshnaik! Below an example project with using stopPropagation()
. Maybe you can see what is the difference with your project.
https://playcanvas.com/project/694477/overview/block-world-input-with-ui
1 Like
@Albertos
Instead of click
event here, I changed to mousedown
and it worked fine. Thank you.
But still I would like to know why it didn’t work for click
event.
1 Like
Ah, click is fired when there is a mouse down and mouse up event on the same element. As the ball jump is done on the mouse down event, it would happen before the click event is fired.
1 Like
event.event.defaultPrevented = true;
this line of code removes the above error