It have z-index: 5. You can change z-index to -1 on !stick.pressed. And set listeners on your main canvas which bring back z-index for virtual joystick’s canvas.
I don’t like this solution, sounds like a hack. Need to think more.
Hi, I was inspired by your issue because it also concerns me. The fact that VirtualJoystick creates an additional canvas that overlays the main renderCanvas of our BabylonJS application is undoubtedly a problem for many. I decided to extend my add-on to VirtualJoystick a little further and added two features. You can go through the script, see what you need, and apply my ideas to your application. For simplicity, you can just use the CanvasManager and toggle it when needed in your application. Or you can use the Swipe Switcher add-on and swipe up from the bottom of the screen to display the virtual joystick panel, and swipe down from the bottom of the screen to hide it. This way, you can hide the joysticks during usage to make the area with your main Canvas accessible for clicks.
Look what I just added now:
const stick = new TouchStick(true)
stick.enableSwipeSwitcher(scene)
This code will work assuming that the canvas of your application has an id, while the VirtualJoystick canvas does not. Thus, I obtain the joystick canvas using the following method:
getCanvasWithoutId() {
const canvases = document.body.getElementsByTagName('canvas')
for (let i = 0; i < canvases.length; i++) {
if (!canvases[i].id) {
return canvases[i]
}
}
return null
}
Then, I pass BABYLON.Scene as a parameter to the class, and from the scene, I can easily get the application canvas using scene.getEngine().getRenderingCanvas(). Having obtained two canvases, I then need to switch them based on some events. I attach listeners to both canvases. Shrinking or expanding the joystick canvas based on swipes at the bottom is achieved through the following methods: