Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / effects / SmearingSprite.cs
@小李xl 小李xl on 23 Nov 2023 1 KB 替换翻滚美术素材
  1.  
  2. using Godot;
  3.  
  4. /// <summary>
  5. /// 拖影精灵
  6. /// </summary>
  7. public partial class SmearingSprite : Sprite2D, IPoolItem
  8. {
  9. public bool IsRecycled { get; set; }
  10. public string Logotype { get; set; }
  11. public bool IsDestroyed { get; set; }
  12.  
  13. private double _timeOut = -1;
  14. private double _totalTime = 0;
  15.  
  16. /// <summary>
  17. /// 从 ActivityObject 的 AnimatedSprite 中复制动画帧
  18. /// </summary>
  19. public void FromActivityObject(ActivityObject activityObject)
  20. {
  21. var currentTexture = activityObject.GetCurrentTexture();
  22. Texture = currentTexture;
  23. Offset = activityObject.AnimatedSprite.Offset;
  24. GlobalPosition = activityObject.AnimatedSprite.GlobalPosition;
  25. GlobalScale = activityObject.AnimatedSprite.GlobalScale;
  26. GlobalRotation = activityObject.AnimatedSprite.GlobalRotation;
  27. }
  28.  
  29. /// <summary>
  30. /// 设置显示的时间, 过期会自动回收
  31. /// </summary>
  32. public void SetShowTimeout(float time)
  33. {
  34. _totalTime = time;
  35. _timeOut = time;
  36. }
  37.  
  38. public override void _Process(double delta)
  39. {
  40. if (_timeOut > 0)
  41. {
  42. _timeOut -= delta;
  43. Modulate = new Color(1, 1, 1, (float)(_timeOut / _totalTime));
  44. if (_timeOut <= 0)
  45. {
  46. ObjectPool.Reclaim(this);
  47. }
  48. }
  49. }
  50.  
  51. public void Destroy()
  52. {
  53. if (IsDestroyed)
  54. {
  55. return;
  56. }
  57.  
  58. IsDestroyed = true;
  59. QueueFree();
  60. }
  61. public void OnReclaim()
  62. {
  63. GetParent().RemoveChild(this);
  64. }
  65.  
  66. public void OnLeavePool()
  67. {
  68. Modulate = Colors.White;
  69. }
  70. }