Topic was automatically imported from the old Question2Answer platform.
Asked By
ulty
Old Version
Published before Godot 3 was released.
I’m trying to create a simple 2D split screen platformer, which supports 2 players that have each their own camera following them. I think I have to use multiple viewports with a shared world but have no idea how to set this up.
Could someone give a basic example on how this would be done ?
To create a split screen you need 4 scenes.
Scene one is your game scene with the world and all game objects including the player objects.
The second scene you create is the view. At this scene you need a Node as root element. This root element need two Panels. At this Panels we draw the game. That’s the reason why you must organize the position and size as the splits screen should look like.
The next step is to create two scenes. You need this scenes to connect your world with the view. The root node of this two scenes are a Viewport. The Viewport at the scenes has two Children. As the first children you add your game world and second children is a camera.
Now you must write a little script for the camera. At this script you say what object you want look with the camera. Scene one with viewport and camera one should look to player one.Scene two with viewport and camera two should look to player two.
Next you activate the current point at your cameras.
At the last step you go to your view scene and add at the Panel, which should show player one, the scene where the camera is focused at player one.
Now you make the same thing with the Panel which should draw the world around player two. Add to the Panel the scene where the camera is focused at player two.
If I have say clearly what I mean and you have all done correct, you should have a split screen. At the moment it is the easiest way to create split screen that I know.
That’s quite a good high level description of what you need to do to get a split screen setup working, but for the ‘game scene’ itself, I found that it’s better to make it an autoloaded scene, than just add it to the scene with the player-n camera directly.
Otherwise you can end up with duplicates of game scene objects and data.
Juan Alpaca
September 14 at 2:01pm
User Faless (sorry man, no idea what your real name is) fixed Viewport to make it easier to do 2D split screen, so I copiend and added a couple lines of code to the platformer demo to make it split screen too. It's pretty straightforward.
You can get it from godot-demos repository, and you need latest Godot head.
This has changed for 3.0.
The simplest Node setup to achieve this in 3D is as follows:
Root Node
|ViewportContainerNew for 3.0
||Viewport
|||Camera
|ViewportContainer2
||Viewport
|||Camera
To make this functional, I had to set Stetch property on for both ViewportContainers.
This will work when the project is played. The ViewportContainers appeared black in the 2D editor view until Godot was closed and re-opened. Only then would it display properly when editing.