2020-09-21 18:45:28 +00:00
|
|
|
extends Camera2D
|
|
|
|
|
|
|
|
|
|
|
|
onready var player = get_node("/root/Map1/Player")
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
|
|
|
pass
|
|
|
|
|
2020-09-21 19:25:56 +00:00
|
|
|
var once = true
|
|
|
|
var lockedPlayerCamera = false
|
2020-09-21 18:45:28 +00:00
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
|
|
|
CameraToPlayer()
|
2020-09-21 19:25:56 +00:00
|
|
|
if once:
|
|
|
|
AnimateMoveCamera(player.position, Vector2(player.position.x - 10,player.position.y - 10), "position", 2)
|
|
|
|
once = false
|
2020-09-21 18:45:28 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
#Move camera to position
|
|
|
|
func MoveCamera(x, y):
|
|
|
|
position.x = x
|
|
|
|
position.y = y
|
|
|
|
|
2020-09-21 19:25:56 +00:00
|
|
|
func _on_Tween_tween_completed(object, key):
|
|
|
|
print(object, key)
|
|
|
|
lockedPlayerCamera = false
|
2020-09-21 18:45:28 +00:00
|
|
|
|
2020-09-21 19:25:56 +00:00
|
|
|
func AnimateMoveCamera(source, destination, key, time):
|
|
|
|
lockedPlayerCamera = true
|
|
|
|
var tween = get_node("/root/Map1/Tween")
|
|
|
|
tween.interpolate_property(get_node("/root/Map1/Camera2D"), key, source, destination, time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
|
|
|
tween.start()
|
|
|
|
|
2020-09-21 18:45:28 +00:00
|
|
|
|
|
|
|
#Move camera close to player
|
|
|
|
func CameraToPlayer():
|
2020-09-21 19:25:56 +00:00
|
|
|
if lockedPlayerCamera == false:
|
|
|
|
MoveCamera(player.position.x, player.position.y)
|