Button OnPointerDownObservable Only Works Once?

https://www.babylonjs-playground.com/#AUXCUE#8

In this playground, I should be able to click on the button and have the color change back and forth. However, it only works once per “run” of the playground. What’s going on? If I swap tabs back and forth and click again, the console logs the pointerdown event, but no color changes. Is this expected behavior? How can I get the button color to swap each click?

Thanks,

Hi,
Here is a partial answer to your questions:
For the change color problem, you made a mistake in the if statement (line 34) : = instead of ===

1 Like

Yes was about to mention what @LeJohn said, but also noticed it works with Button but not Ellipse …
https://www.babylonjs-playground.com/#AUXCUE#10

1 Like

@iblis it works with Ellipse container only if isPointerBlocker = true
https://www.babylonjs-playground.com/#AUXCUE#11

I wasn’t aware of this myself, but it seems the reason for this is documented here.

By default containers do not block pointer events (ie. the underlying scene will receive the pointer event even if the pointer is over a container). You can prevent this behavior by calling container.isPointerBlocker = true .

4 Likes

It worked this way for me


If you want it to run 1 time use:
Captura de pantalla_2020-07-09_08-14-57
If you want to be constantly checked use.
Captura de pantalla_2020-07-09_08-15-29
Son observables en la documentación esta explicado como funcionan.
They are observable in the documentation is explained how they work.
https://doc.babylonjs.com/how_to/observables

silly mistake, my bad.

Seemms to be the solution. I actually saw this but I thought it meant the opposite.

Interestingly enough if you enter Chrome console and toggle device toolbar everything works fine in that view, without needing to change isPointerBlocker to true.