Is there any way to fix this? when I change the resolution of the game, the pipe position just not in the middle anymore, here’s my window settings and a video about the bug
PlayerScreen.gd
extends Node2D
@export var pipe_scene: PackedScene
var time: float = 0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
time += delta
if time > 1:
print(DisplayServer.window_get_size())
var pipe = pipe_scene.instantiate()
pipe.global_position = get_viewport().size / 2
add_child(pipe)
time = 0.
pipe.gd
extends CharacterBody2D
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta):
position.x -= 100 * delta
move_and_slide()
“Is there any way to fix this? when I change the resolution of the game, the pipe position just not in the middle anymore, here’s my window settings and a video about the bug”
The minimal code example spawns the new objects in the middle and keeps the position width ratio of the existing circles. Hence question answered and problem solved.
I definately recommend you read the docs about multiple resolutions. Maybe that can help you and answer the additional questions you have.
Whenever you change the resolution of a running game, you should stop drawing until you finished what you have to do with the new resolution. In singleplayer game you would pause the game do whatever you need to do and than let the gameloop continue.
EDIT: Some other thoughts that might be worth thinking about: