0
\$\begingroup\$

My problem is that my game is made for a 320 by 320 window. When I try to upscale it I run into problems. The camera's movement is all wrong.

When it snaps to a new position it snaps to a grid position of (2, 0) instead of (1,0) when I reach the edges of a grid box. I am not sure what is causing this skipping during camera movement.

extends Camera2D

var grid_pos = Vector2(0,0)
var grid_size = Vector2(320,320)
onready var HUD = get_node("/root/dungeon/HUD")
signal room_trigger(pos)

var screen_is_shaking = false

func _ready():
    connect("room_trigger",HUD, "display_dialog")

func _process(delta):
    var player_grid_pos = get_grid_pos(get_parent().global_position)

    global_position = player_grid_pos * Vector2(320,320)

    if player_grid_pos != grid_pos:
        grid_pos = player_grid_pos
        emit_signal("room_trigger", grid_pos)


    if screen_is_shaking:
        screen_shake()

func get_grid_pos(pos):

    var x = round(pos.x/ grid_size.x)
    var y = round(pos.y/ grid_size.y)

    return Vector2(x,y)

func _on_Timer_timeout():
    screen_is_shaking = false
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.