godot-ex1/World/Grass.gd

24 lines
742 B
GDScript

extends Node2D
const GrassEffect = preload("res://Effects/GrassEffect.tscn")
func destroy_effect():
var grass_effect = GrassEffect.instance()
var world_node = get_tree().current_scene
# We add the effect to the world and not to the grass itself since
# we're going to free the current node later.
# The better way to do it is to add the animated sprite in the same seen
# as the grass statically and just play the animation here and disable the it's
# interaction with the world such as hurt box
world_node.add_child(grass_effect)
# set the position of the effect to the global_position of the current grass
grass_effect.global_position = global_position
func _on_HurtBox_area_entered(_area):
destroy_effect()
queue_free()