Reputation: 87
I currently develop a game where the player moves a camera over a tilemap map to navigate. Unfortunatley as shown in the video below, the textures look weird when the camera is moving and I don’t know how to make them look sharp.
video: https://www.loom.com/share/f98c47207a0b4dcaaeae621ef1b028d9?sid=a6128b25-aa58-43ce-a140-26a17a07b743
Code of camera scene:
extends Camera2D
# Zoom variables
var min_zoom = Vector2(1, 1)
var max_zoom = Vector2(2, 2)
var desired_zoom = zoom
# Movement variables
var camera_speed = 500
# Map boundaries
var min_x_pos = 0
var max_x_pos = 2560
var min_y_pos = 0
var max_y_pos = 1360
func _physics_process(delta):
if global_position != get_camera_position(delta):
global_position = get_camera_position(delta)
# var tween = create_tween()
# tween.tween_property(self, "global_position", get_camera_position(delta), .2)
func _unhandled_input(event):
if event.is_action_pressed("zoom_in"):
desired_zoom = zoom + Vector2(.25, .25)
if desired_zoom <= max_zoom and desired_zoom >= min_zoom:
var tween = create_tween()
tween.tween_property(self, "zoom", desired_zoom, .08)
elif event.is_action_pressed("zoom_out"):
desired_zoom = zoom - Vector2(.25, .25)
if desired_zoom <= max_zoom and desired_zoom >= min_zoom:
var tween = create_tween()
tween.tween_property(self, "zoom", desired_zoom, .08)
func get_camera_position(delta):
var new_camera_position = global_position
if Input.is_action_pressed("ui_right") and new_camera_position.x <= 1984:
new_camera_position.x += camera_speed * delta
if Input.is_action_pressed("ui_left") and new_camera_position.x >= 400:
new_camera_position.x -= camera_speed * delta
if Input.is_action_pressed("ui_up") and new_camera_position.y >= 292:
new_camera_position.y -= camera_speed * delta
if Input.is_action_pressed("ui_down") and new_camera_position.y <= 1068:
new_camera_position.y += camera_speed * delta
return new_camera_position
Upvotes: 1
Views: 73
Reputation: 87
I don't really know how I fixed it, but the jitter is gone now. I just played around with position snapping and the position smoothing option of the camera. I know have position smoothing toggled on and it is working perfectly.
Upvotes: 1