Camera Animation works now

This commit is contained in:
EljakimHerrewijnen 2020-09-21 21:25:56 +02:00
parent 5e5547f4a2
commit c5aa58c16d
2 changed files with 18 additions and 12 deletions

View File

@ -7,11 +7,14 @@ onready var player = get_node("/root/Map1/Player")
func _ready(): func _ready():
pass pass
var once = true
var lockedPlayerCamera = false
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
CameraToPlayer() CameraToPlayer()
# TestCamera() if once:
AnimateMoveCamera(player.position, Vector2(player.position.x - 10,player.position.y - 10), "position", 2)
once = false
pass pass
#Move camera to position #Move camera to position
@ -19,16 +22,18 @@ func MoveCamera(x, y):
position.x = x position.x = x
position.y = y position.y = y
func _on_Tween_tween_completed(object, key):
print(object, key)
lockedPlayerCamera = false
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()
func TestCamera():
var t = player.position
t.x = 100
t.y = 100
MoveCamera(t.x, t.y)
# var tween = get_node("/root/Map1/Tween")
# tween.interpolate_property(get_node("/root/Map1/Camera2D"), "position", player.position, t, 200, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
# tween.start()
#Move camera close to player #Move camera close to player
func CameraToPlayer(): func CameraToPlayer():
if lockedPlayerCamera == false:
MoveCamera(player.position.x, player.position.y) MoveCamera(player.position.x, player.position.y)

File diff suppressed because one or more lines are too long