Your question is a bit vague, I'd recommend adding a bit more context to get a better answer, however, making some assumptions about your question, here is my advice.
- Create a root node
Node2D
in the 2D scene.
- Create a
KinematicBody2D
as a child of the root.
- Create a
CollisionShape2D
as a child of that.
- Create a
Sprite
, also as a child of the KinematicBody2D
, and assign a texture.
- Add a shape to the
CollisionShape2D
and adjust it to fit your sprite.
- Create a
Camera2D
, also as a child of the KinematicBody2D
.
- Create some background assets under the root
Node2D
as appropriate.
Add the following code to the KinematicBody2D
...
extends KinematicBody2D
var dragging = false
func _ready():
set_process_input(true)
func _input(event):
if event is InputEventMouseButton:
if event.is_pressed():
dragging = true
else:
dragging = false
elif event is InputEventMouseMotion and dragging:
position = get_global_mouse_position()
Make the Camera2D
current by selecting the flag, and optionally enable or disable the Drag Margin flags, depending on how you want it to move.
That should do it, if you drag the sprite around now, the camera should follow. You may find it a bit difficult to control, so it might be wise to add some speed control or something, depending on the effect you're after.
For reference, I've put a simple sample project here that shows what I've just described.