I have a problem that looks like a bug in BABYLON.GUI to me but I’m posting it in Questions for now as maybe it’s intended behaviour and there is a way around the problem.
I have some code that changes cursor in various situations, using code like that:
engine.getRenderingCanvas().style.cursor = “url(’…/images/some_cursor_image.png’) 12 12, auto”;
I have scene.doNotHandleCursors set to true and it all worked perfectly fine until I added this code at some point in my application:
BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI(“UI”);
Now, the change of the cursor happens for an extremely brief moment but any time mouse moves, the cursor is changed back to default.
It looks that the culprit is this code:
this._changeCursor("");
in babylonjs.gui.js that seems to be called on every pointer move.
I think this code should be enclosed in
if (!scene.doNotHandleCursors) clause, as it’s done in other places.
I can’t see an easy way around the problem, an obvious solution would be to change cursor every frame, after ADT does it but that seems very inefficient (particularly as cursor image is a png that needs to be loaded, I’m pretty sure browsers cache it but still).
Any ideas how to get around the problem? Or is it a bug and I should just report it as a bug?
Wow! That was fast
I pointed my application to the latest preview release of Babylon.GUI and all my cursors now work perfectly fine!
Thanks @msDestiny14 for an exteremely quick bugfix!
Btw, you probably all know that, but Babylon.js is an amazing engine! I am converting a relatively complex game from 2D (using plain canvas) to 3D (using Babylon.js) and it goes surprisingly smoothly. What is particularly great is that I don’t need to adapt my game to how the framework wants it (which is unfortunately common for many frameworks and is a real pain if you have existing code), I can still keep my game loop and only change drawing code, code that deals with selecting things and stuff like that while keeping most of the code intact.
Thanks for welcoming me to the forums and thanks again for the quick fix!
Question–what is the general rationale behind the scene setting cursor to default when mousing over meshes that contain GUI elements? And is there a way to prevent this from happening, other than scene.doNotHandleCursors = true?
What is the recommended approach for use cases where we want the cursor to remain whatever it currently is when mousing over a specific GUI, while retaining the scene’s general ability to change cursors?