Skip to content

Instantly share code, notes, and snippets.

@neikeq
Last active August 2, 2016 15:41
Show Gist options
  • Save neikeq/48045d8037a79830c846a22796926b9f to your computer and use it in GitHub Desktop.
Save neikeq/48045d8037a79830c846a22796926b9f to your computer and use it in GitHub Desktop.
WARNING: Should modify the camera offset instead of its position. Check: https://gist.github.com/blurymind/18c08bd2a617eeb102ed237c0d62ae85
extends Camera2D
var dragging = false
var drag_from = Vector2()
func _ready():
set_process_unhandled_input(true)
func _unhandled_input(event):
if event.type == InputEvent.MOUSE_BUTTON and not event.is_echo():
if event.pressed:
drag_from = event.pos
dragging = true
else:
dragging = false
elif event.type == InputEvent.MOUSE_MOTION and dragging:
translate(drag_from - event.pos)
drag_from = event.pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment