Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / effects / AutoDestroySprite.cs
@小李xl 小李xl on 18 Sep 2023 868 bytes 近战反弹抵消子弹和反弹子弹
  1. using Godot;
  2. using Godot.Collections;
  3.  
  4. /// <summary>
  5. /// 到期自动销毁的帧动画
  6. /// </summary>
  7. public partial class AutoDestroySprite : AnimatedSprite2D
  8. {
  9. /// <summary>
  10. /// 延时销毁时间
  11. /// </summary>
  12. [Export]
  13. public float DelayTime { get; set; } = 1f;
  14. /// <summary>
  15. /// 子节点包含的例子特效, 在创建完成后自动播放
  16. /// </summary>
  17. [Export]
  18. public Array<GpuParticles2D> Particles2D { get; set; }
  19. public override async void _Ready()
  20. {
  21. var sceneTreeTimer = GetTree().CreateTimer(DelayTime);
  22. if (Particles2D != null)
  23. {
  24. foreach (var gpuParticles2D in Particles2D)
  25. {
  26. gpuParticles2D.Emitting = true;
  27. }
  28. }
  29. await ToSignal(sceneTreeTimer, Timer.SignalName.Timeout);
  30. QueueFree();
  31. }
  32. }