1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-25 17:44:24 +00:00

Add spawner and SpawnedEntities

This commit is contained in:
Lorenzo Rossi 2024-04-14 19:48:13 +02:00
parent 8f46ff5022
commit 2fc4f9e91a
3 changed files with 26 additions and 0 deletions

18
behaviours/spawner.gd Normal file
View file

@ -0,0 +1,18 @@
extends Node2D
class_name Spawner
signal spawned(entity: Node2D)
@export var scene: PackedScene
@export var parent: Node2D
func spawn():
var entity = scene.instantiate()
entity.global_scale = global_scale
entity.global_position = global_position
entity.global_rotation = global_rotation
parent.add_child(entity)
func _ready():
if parent == null:
parent = MainGame.get_ancestor(self).get_node("SpawnedEntities")

6
behaviours/spawner.tscn Normal file
View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://cyrg770fsetyu"]
[ext_resource type="Script" path="res://behaviours/spawner.gd" id="1_b4uk0"]
[node name="Spawner" type="Node2D"]
script = ExtResource("1_b4uk0")

View file

@ -66,3 +66,5 @@ position = Vector2(-135, -134)
[node name="Sheep2" parent="." instance=ExtResource("5_63bwb")] [node name="Sheep2" parent="." instance=ExtResource("5_63bwb")]
position = Vector2(-462, -77) position = Vector2(-462, -77)
[node name="SpawnedEntities" type="Node2D" parent="."]