godot 游戏实例位置

问题描述 投票:0回答:1

我正在制作一款多人游戏,正在运行该游戏的 2 个实例,我希望从编辑器开始时,这些实例的窗口彼此并排显示(其中一个位于屏幕的地板上)左边,另一个在右边屏幕的地板上)。

我知道你可以在编辑器中调整游戏窗口的位置,但是对于2个实例如何做到这一点?

godot godot4
1个回答
0
投票

我遇到了同样的问题,根据 KonstantinosPetrakis 对此问题的评论https://github.com/godotengine/godot-proposals/issues/3357,我想出了以下解决方案:

func _adjust_both_windows():
    randomize()
    await get_tree().create_timer(randf_range(0,1)).timeout
    var the_path = 'user://lil_number.tres'
    var save_the_value = func(val): 
        var the_file = FileAccess.open(the_path, FileAccess.WRITE)
        the_file.store_64(val)
        the_file.flush()
        the_file.close()
    var read_value = func():
        if FileAccess.file_exists(the_path):
            await get_tree().create_timer(.5).timeout
            var the_file = FileAccess.open(the_path, FileAccess.READ)
            var the_value = the_file.get_64()
            the_file.close()
            return the_value
        return 0 
    var the_value = await read_value.call()
    save_the_value.call(the_value + 1)
    get_window().size = get_window().size*0.75
    if (the_value % 2 == 0):
        get_window().position.x = 0
    else:
        get_window().position.x = get_window().size.x

这样您就可以:

func _ready():
    _ajustar_las_ventanas()

您已准备好开始(但是,您可能需要调整一些值)。我希望这对某人有帮助,但似乎这很快就会成为过去的问题,因为我读到下一个 Godot 版本将提供查找和控制多个会话实例的设施🤷u200d♂️

© www.soinside.com 2019 - 2024. All rights reserved.