further elaboration on bullets
This commit is contained in:
parent
da9111bcf2
commit
393c3b670a
16 changed files with 218 additions and 29 deletions
|
|
@ -4,6 +4,10 @@ class_name Bullet
|
|||
extends Area2D
|
||||
|
||||
|
||||
## Emitted whenever a bullet is recycled.
|
||||
signal recycled()
|
||||
|
||||
|
||||
## The number of bullets to allocate at startup.
|
||||
const INITIAL_ALLOCATED_BULLETS: int = 2000
|
||||
|
||||
|
|
@ -51,9 +55,10 @@ static func create(
|
|||
direction: Vector2 = Vector2.RIGHT,
|
||||
face_direction: bool = false,
|
||||
) -> Bullet:
|
||||
var bullet: Bullet = _cached_bullets.pop_back()
|
||||
if not bullet:
|
||||
bullet = Bullet.new()
|
||||
#var bullet: Bullet = _cached_bullets.pop_back()
|
||||
#if not bullet:
|
||||
#bullet = Bullet.new()
|
||||
var bullet := Bullet.new()
|
||||
|
||||
bullet.texture = texture
|
||||
bullet.hitbox_size = hitbox_size
|
||||
|
|
@ -67,8 +72,11 @@ static func create(
|
|||
## Removes the bullet from the scene tree and returns it to the bullet cache to be
|
||||
## re-used later.
|
||||
func recycle() -> void:
|
||||
get_parent().remove_child(self)
|
||||
_cached_bullets.append(self)
|
||||
#if is_inside_tree():
|
||||
#get_parent().remove_child(self)
|
||||
#_cached_bullets.append(self)
|
||||
queue_free()
|
||||
recycled.emit()
|
||||
|
||||
|
||||
static func _static_init() -> void:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue