#Best way to add zooming and movement control in a 2d sandbox game[ragdoll]

1 messages · Page 1 of 1 (latest)

sudden herald
#

i added the script in the camer a ,, but how to like keep the bakground static , i mean the camera script should not efefct the texturerect

this is the script ```extends Node

var camera: Camera2D
var zoom_speed = 0.1
var min_zoom = -5
var max_zoom = 2.0

func _ready():
camera = Camera2D.new()
add_child(camera)
camera.make_current()
#func _ready():
#camera = Camera2D.new()
#add_child(camera)
#camera.make_current()
#camera.limit_left = 0
#camera.limit_top = 0
#camera.limit_right = 1920 # Match your viewport width
#camera.limit_bottom = 1080

func _input(event):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
camera.zoom = Vector2.ONE * min(camera.zoom.x + zoom_speed, max_zoom)
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
camera.zoom = Vector2.ONE * max(camera.zoom.x - zoom_speed, min_zoom)

grave jasper
#

You want the background to follow the camera or to stay where it is as the camera moves?

sudden herald
grave jasper
#

I just realized you said you are using a TextureRect. TextureRect and other Control nodes are meant to follow the camera as they are made for UI elements.

Try using a Sprite2D instead.