godot

Godot Game With 2 Windows for Player and Game Master


I need 2 windows in my my game, one window shows the normal game and the second window is a game master view that will show the same content from the same perspective but with extra information such as hit boxes any maybe some text with stats. The normal window will be dragged on to a second monitor and maximized while the game master window will remain on the primary monitor, remain windowed, and moved around and resized. The game itself is currently 2D but I'll soon be adding 3D objects.

I followed this tutorial, https://github.com/geegaz/Multiple-Windows-tutorial?tab=readme-ov-file#contents-of-this-repository, and was able to get my game master window working but it won't scale the contents. Even as my normal window scales it's content the content in the game master window appears to stay scaled to the original size of the normal window and I only see the upper left corner of the content.

I'm also not sure if this will allow me to selectively render elements on the normal window and the game master window. My original implementation of this was a PyQt application that simply drew the game twice, once in normal mode and once in game master mode.


Solution

  • Eventually I realized that what I'm trying to do is more similar to a Split screen game which this video explains how to do, https://www.youtube.com/watch?v=tkBgYD0R8R4. By replacing SubViewports with Windows I was able to render into separate windows. On the game master window I set content_scale_mode to Canvas Items and content_scale_aspect to Keep and then in gdscript I wrote.

    func resize() -> void:
        %GameMasterView.content_scale_size = Vector2i(get_window().size)
        get_viewport().size = get_window().size
        
    # Called when the node enters the scene tree for the first time.
    func _ready() -> void:
        get_tree().get_root().size_changed.connect(resize) 
        resize()
    

    At this point the view was being properly reproduced in the second window.

    I struggled for a long time with showing extra details on the game master view. I tried to set the following up.

    and then I set the SubViewport Canvas Cull Mask to 1 and the WindowCanvas Cull Mask to 1 and 2. All my game master only items had their visibility layer set to 2. But for some reason it seemed that the Window couldn't render anything that wasn't rendered in the SubViewport. Eventually I Reduced it to just.

    and in a gdscript I callled get_window().canvas_cull_mask = 1 to set the cull mask on the default viewport and this worked.