a game about throwing hammers made for the github game off
fix enemydeatheffect
bendn 2022-12-01
parent 3929790 · commit 1854740
-rw-r--r--autoloads/Utils.gd14
-rw-r--r--fx/enemy_death.gd6
2 files changed, 12 insertions, 8 deletions
diff --git a/autoloads/Utils.gd b/autoloads/Utils.gd
index 19db63f..ca16daa 100644
--- a/autoloads/Utils.gd
+++ b/autoloads/Utils.gd
@@ -22,11 +22,17 @@ static func value_types(arr: Array) -> Array:
static func is_in_range(val: float, start: float, end: float) -> bool:
return val >= start and val <= end
+static func instance(n: Node, on: Node) -> Node:
+ on.add_child(n)
+ return n
+
static func instance_scene(scene: PackedScene, position: Vector2, on: Node) -> Node:
- var instance := scene.instantiate() as Node2D
- on.add_child(instance)
- instance.global_position = position
- return instance
+ var n := scene.instantiate() as Node2D
+ n.global_position = position
+ return Util.instance(n, on)
+
+func instance_on_main(n: Node) -> Node:
+ return Util.instance(n, get_tree().current_scene)
func instance_scene_on_main(scene: PackedScene, position: Vector2) -> Node:
return Util.instance_scene(scene, position, get_tree().current_scene)
diff --git a/fx/enemy_death.gd b/fx/enemy_death.gd
index 969eaff..510e518 100644
--- a/fx/enemy_death.gd
+++ b/fx/enemy_death.gd
@@ -3,12 +3,10 @@ extends Node2D
const DustFx := preload("./dust.tscn")
func _ready() -> void:
- # print(global_position)
randomize()
- # print_stack()
- # get_tree().paused = true
var randv := func randv(): return Vector2(randf_range(-10, 10), randf_range(-10, 10))
for i in range(10):
- var inst := Utils.instance_scene_on_main(DustFx, global_position + randv.call())
+ var inst := Utils.instance_on_main(DustFx.instantiate()) as Node2D
+ inst.global_position = global_position + randv.call()
if i == 9:
inst.tree_exited.connect(queue_free)