The input response of BABYLON.GUI and BABYLON.Camera becomes a bit buggy when I have one Scene with multiple Viewports and multiple active Cameras and multiple GUIs.
- Do you perhaps know of solutions for one or more of the bugs listed below?
Then I’d be happy to know about your suggestions to fix!
Instructions to reproduce
I made a playground to demonstrate the GUI input (click) problem:
- Click the red button in the lower half Viewport in center of button control. That will also trigger the green button shown in the upper half Viewport (but not rendered in the lower half Viewport due to layerMasks set).
- I made the 2 buttons slightly different size so you can test on the edges (above/below or left/right) to experiment with when 1 or the other button only triggers (hit-test)
- The CameraInput (pan/zoom/rotate etc.) also responds to click & drags outside its viewport. Would expect the CameraInput only respond to clicks started within its Viewport. Now both Cameras respond to 1 click&drag as if in sync (quite annoying).
- The aspect ratio of the GUI Controls rendered get messed up (compared to 1 camera and 1 full screen viewport) if it is not rendered in same ratio of the whole canvas. For example lower half Viewport GUI seems shrunk by 50% in vertical axis.
- In the upper half Viewport clicks/touches on GUI elements don’t respond at all.
- See comments in Playground code to experiment/test further.
I’m working on split-screen local (“same couch”) multiplayer support for my game. Which is actually quite nice feature for any developer probably, because then one can deploy his/her game easily also to consoles as well. Consoles typically have multiple players within the same physical room, each player having controller/input device… so no need to ‘wait’ for other remote players to join (they are already in the house).
As solution intent for split-screen mode, I chose to use only 1 scene and multiple camera/viewport/gui approach. Because then I can easily make it 2, 3 or 4 etc. player split-screen with very little code effort. No need to duplicate scene and objects etc. as each player is just an extra Camera and Viewport and GUI (visible only to that Camera and in that Viewport) enabled/disabled. And then I can quickly switch between number of players/viewports during gameplay.
E.g. in 4 player battle last-man-standing game in split-screen (4x 25% screen), when player 3 and 4 are Game Over, then split-screen reduces immediately to 2 player (2x 50% screen). The Camera for game over player 3 and 4 are then deactivated, and their GUIs rootContainer visibility will be set to false, to save on render time.