Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / effects / Blood.cs
  1. using Godot;
  2.  
  3. /// <summary>
  4. /// 血液溅射效果
  5. /// </summary>
  6. public partial class Blood : CpuParticles2D
  7. {
  8. private float _timer;
  9. public override void _Ready()
  10. {
  11. Emitting = true;
  12. ReadyStop();
  13. }
  14.  
  15. public override void _Process(double delta)
  16. {
  17. _timer += (float)delta;
  18. if (_timer > 15f)
  19. {
  20. if (_timer > 60f)
  21. {
  22. QueueFree();
  23. }
  24. else
  25. {
  26. var color = Modulate;
  27. color.A = Mathf.Lerp(1, 0, (_timer - 15f) / 45f);
  28. Modulate = color;
  29. }
  30. }
  31. }
  32.  
  33. private async void ReadyStop()
  34. {
  35. var timer = GetTree().CreateTimer(Lifetime - 0.05f);
  36. await ToSignal(timer, "timeout");
  37. Emitting = false;
  38. SetPhysicsProcess(false);
  39. SetProcessInput(false);
  40. SetProcessInternal(false);
  41. SetProcessUnhandledInput(false);
  42. SetProcessUnhandledKeyInput(false);
  43. }
  44. }