0 votes

I have a tilemap and want it to go with my dragging. Exactly as it is in Clash of Clans. I have no idea how to do.

Godot version 3.2.3.stable
in Engine by (378 points)

It is unclear what you exactly want to accomplish. Do you mean move the camera along a TileMap in the scene?

It would be better if the tilemap would move because else, I'd have to move everything (Control Nodes and so on) with the camera.

2 Answers

0 votes
Best answer

It's even easier than Lopy's solution with a new action. It exists InputEventScreenDrag. Then, one must just enable "Emulate Touch From Mouse" in the Settings and combine event.relative with the current position.

by (378 points)
0 votes

You can implement dragging with something like that :
func _unhandled_input(event):
. if event is InputEventMouseMotion:
. . if Input.is_action_pressed("drag_screen"):
. . . print(event.relative)
Note that you have to add a "drag_screen" action in your projects settings, Input Map tab. You could check for left click directly, but it would prevent your user from easily remapping afterwards.

You can try moving the TileMap and the Camera, to see which is more practical.

by (2,482 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.