D3/Char/Char_Components/fx_component.gd
2025-05-10 23:19:52 +08:00

61 lines
1.9 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#挂在角色身上由角色产生的可以由角色调用产生相应的fx效果
#包括:地面扬尘、蹬墙跳特效
extends Node2D
# 预加载场景
@export var FLOOR_DUST = preload("res://Char/Char_Components/Floor_Wall_FX/floor_dust.tscn")
@export var WALL_JUMP_DUST = preload("res://Char/Char_Components/Floor_Wall_FX/wall_jump_dust.tscn")
func create_floor_dust(direction: int):
# 实例化floor_dust场景
var dust = FLOOR_DUST.instantiate()
# 获取Level节点
var level = get_tree().get_first_node_in_group("Level")
if not level:
push_warning("No level node found in group 'Level'")
return
# 获取或创建Effect_Group节点
var effect_group = level.get_node_or_null("Effect_Group")
if not effect_group:
effect_group = Node2D.new()
effect_group.name = "Effect_Group"
level.add_child(effect_group)
# 设置灰尘特效的位置和方向
dust.global_position = global_position
# 根据传入的direction参数设置特效的朝向
dust.scale.x = -1 if direction == -1 else 1
# 将灰尘特效添加为Effect_Group的子节点
effect_group.add_child(dust)
func create_wall_jump_dust(direction: int):
# 实例化wall_jump_dust场景
var dust = WALL_JUMP_DUST.instantiate()
# 获取Level节点
var level = get_tree().get_first_node_in_group("Level")
if not level:
push_warning("No level node found in group 'Level'")
return
# 获取或创建Effect_Group节点
var effect_group = level.get_node_or_null("Effect_Group")
if not effect_group:
effect_group = Node2D.new()
effect_group.name = "Effect_Group"
level.add_child(effect_group)
# 获取wall_jump_dust的生成位置
var spawn_pos = $pos_wall_jump_dust.global_position
# 设置灰尘特效的位置和方向
dust.global_position = spawn_pos
# 根据传入的direction参数设置特效的朝向
dust.scale.x = -1 if direction == -1 else 1
# 将灰尘特效添加为Effect_Group的子节点
effect_group.add_child(dust)