preload hit scene on player load instead of per hit

This commit is contained in:
yuki 2025-11-18 18:23:02 -03:00
parent 4fd1b4dc17
commit 75b2edc212
2 changed files with 3 additions and 2 deletions

View file

@ -5,6 +5,7 @@ const DEADZONE: float = 0.1
@export var id: int = 1
@export var max_speed: float = 90
@onready var hit_scene: PackedScene = preload("res://scenes/hit/power_hit.tscn")
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var anim_player: AnimationPlayer = $AnimationPlayer
@onready var state_machine: StateMachine = $StateMachine

View file

@ -40,7 +40,7 @@ func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
var hit_node: Hit
if hit_type == "left" or hit_type == "right":
hit_node = preload("res://scenes/hit/small_hit.tscn").instantiate()
hit_node = player.hit_scene.instantiate()
# flip entire node horizontally if spawning left
# flip vertically if player 2
hit_node.scale = Vector2(
@ -57,7 +57,7 @@ func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
(sprite_texture.get_height()*-1) if player.id == 1 else 4
)
elif hit_type == "power":
hit_node = preload("res://scenes/hit/power_hit.tscn").instantiate()
hit_node = player.hit_scene.instantiate()
player.add_child(hit_node)