Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Sprite
- export(float) var speed = 10.0
- export(int) var tileSize = 32
- func _process(delta):
- var dir = get_input_dir()
- if dir != Vector2():
- $Tween.interpolate_property(self, "position", position, position + dir * tileSize, 1.0 / speed, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
- $Tween.start()
- func _on_Tween_tween_started(object, key):
- set_process(false)
- func _on_Tween_tween_completed(object, key):
- set_process(true)
- func get_input_dir():
- var dir = Vector2()
- dir.y = (int(Input.is_action_pressed("ui_down")) - int(Input.is_action_pressed("ui_up")))
- if dir.y == 0:
- dir.x = (int(Input.is_action_pressed("ui_right")) - int(Input.is_action_pressed("ui_left")))
- return dir
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement