mirror of
https://github.com/Steffo99/swear-jar.git
synced 2024-11-25 17:14:20 +00:00
Cache $Area reference in Spawner
This commit is contained in:
parent
cc60fc1ff9
commit
265da5fe50
1 changed files with 4 additions and 5 deletions
|
@ -7,6 +7,8 @@ class_name Spawner
|
||||||
var buffer: int = 0
|
var buffer: int = 0
|
||||||
@export var buffer_cap: int
|
@export var buffer_cap: int
|
||||||
|
|
||||||
|
@onready var area: Area2D = $Area
|
||||||
|
|
||||||
|
|
||||||
func spawn():
|
func spawn():
|
||||||
buffer = clampi(buffer + 1, 0, buffer_cap)
|
buffer = clampi(buffer + 1, 0, buffer_cap)
|
||||||
|
@ -14,14 +16,11 @@ func spawn():
|
||||||
|
|
||||||
func _physics_process(_delta):
|
func _physics_process(_delta):
|
||||||
if buffer > 0:
|
if buffer > 0:
|
||||||
var overlapping_bodies = $Area.get_overlapping_bodies()
|
var overlapping_bodies = area.get_overlapping_bodies()
|
||||||
for overlapping_body in overlapping_bodies:
|
for overlapping_body in overlapping_bodies:
|
||||||
if overlapping_body.collision_layer && 0b100:
|
if overlapping_body.collision_layer && 0b100:
|
||||||
print("[Spawner] Not spawning, overlapping with: ", overlapping_body)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
var scene_instant = scene.instantiate()
|
var scene_instant = scene.instantiate()
|
||||||
scene_instant.position = Vector2.ZERO
|
scene_instant.position = Vector2.ZERO
|
||||||
print("[Spawner] Spawned ", buffer, "/", buffer_cap, ": ", scene_instant)
|
|
||||||
buffer -= 1
|
buffer -= 1
|
||||||
add_child(scene_instant)
|
add_child(scene_instant)
|
||||||
|
|
Loading…
Reference in a new issue