Newer
Older
DungeonShooting / DungeonShooting_Godot / src / test / TestOptimizeSprite.cs
@小李xl 小李xl on 11 Oct 2023 2 KB 日志系统
  1. using Godot;
  2.  
  3. public partial class TestOptimizeSprite : Node2D
  4. {
  5. [Export()] public Texture2D[] ImageList;
  6.  
  7. [Export()] public Label Label;
  8. public override void _Ready()
  9. {
  10. ImageCanvas.Init(GetTree().CurrentScene);
  11. ImageCanvas.MaxHandlerTime = 4;
  12. var scale = 2;
  13. var imageCanvas = new ImageCanvas(1920 / scale, 1080 / scale);
  14. imageCanvas.Scale = new Vector2(scale, scale);
  15.  
  16. var successCount = 0;
  17. for (int i = 0; i < 50000; i++)
  18. {
  19. var texture = Utils.Random.RandomChoose(ImageList);
  20. var x = Utils.Random.RandomRangeInt(0, imageCanvas.Width);
  21. var y = Utils.Random.RandomRangeInt(0, imageCanvas.Height);
  22. var centerX = Utils.Random.RandomRangeInt(0, texture.GetWidth());
  23. var centerY = Utils.Random.RandomRangeInt(0, texture.GetHeight());
  24. var angle = Utils.Random.RandomRangeInt(0, 360);
  25. imageCanvas.DrawImageInCanvas(texture, null, x, y,
  26. angle, centerX, centerY, Utils.Random.RandomBoolean(),
  27. () =>
  28. {
  29. successCount++;
  30. Label.Text = $"当前绘制数量: {successCount}";
  31. }
  32. );
  33. }
  34. // var delta = 360f / (15 * 8);
  35. // var angle = 0f;
  36. // for (int i = 0; i < 15; i++)
  37. // {
  38. // for (int j = 0; j < 8; j++)
  39. // {
  40. // //var texture = Utils.RandomChoose(ImageList);
  41. // var texture = ImageList[1];
  42. // var centerX = texture.GetWidth() / 2;
  43. // var centerY = texture.GetHeight() / 2;
  44. // //var angle = Utils.RandomRangeInt(0, 360);
  45. // //Debug.Log($"x: {i}, y: {j}, angle: " + angle);
  46. // imageCanvas.DrawImageInCanvas(texture,
  47. // 10 + i * 10, 10 + j * 10,
  48. // angle, centerX, centerY, false
  49. // );
  50. // angle += delta;
  51. // }
  52. // }
  53.  
  54. //var texture = ImageList[0];
  55. //imageCanvas.DrawImageInCanvas(texture, imageCanvas.Width / 2, imageCanvas.Height / 2, 0, 0, 0, true);
  56. //imageCanvas.DrawImageInCanvas(texture, imageCanvas.Width / 2, imageCanvas.Height / 2, 0, texture.GetWidth() / 2, texture.GetHeight() / 2, true);
  57.  
  58.  
  59.  
  60. AddChild(imageCanvas);
  61. }
  62. }