9 Adding Pickups, Learning AnimationPlayer

Here we will add Pickup a coin to the game, and we will learn about AnimationPlayer.

AnimationPlayer

AnimationPlayer is the node which allow us to add animation to other nodes, We can animate such by modifying their properties, and providing the key frames.

In the above image, we are working on animation named "jumping", the animation is 1 sec long and is looped. And set to Auto Start.

As you can see there are 5 dimonds shapes. Those are the key frames. In 0 we defined the position, then in 0.4 sec change that position to certain value. It will automatically calculate he intermediate values.

 As in the above image, we choose a time frame (say 0.4) and click in the key in the inspector to set that value for that time.

We made the Coin to bounce. When the player touched it, we simply call the coin_collected function in the player and queue_free()

func _on_area_2d_body_entered(body):
	body.coin_collected()
	queue_free()
	pass # Replace with function body.

queue_free()

queue_free is a method that will destroy this object, once destroyed this will be removed from the scene tree and memory are cleaned up.