A Smoll game engine
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

36 righe
1.3 KiB

  1. using System.Numerics;
  2. using Raylib_cs;
  3. namespace Smoll.Ex2 {
  4. class SpriteComponent : Smoll.Component , IDisposable{
  5. Complex offset;
  6. string asset_name;
  7. Transform2DComponent? ownerTransform;
  8. Texture2D texture;
  9. public SpriteComponent(string asset_name, int offset_x = 0, int offset_y = 0)
  10. {
  11. this.offset = offset_x + Complex.ImaginaryOne*offset_y;
  12. this.asset_name = asset_name;
  13. }
  14. public override void OnAttached() {
  15. ownerTransform = owner.GetComponent<Transform2DComponent>();
  16. Image image = owner.layers.First().attachedEngine.GetModule<RaylibAssetManagerModule>().GetImage(asset_name);
  17. texture = Raylib.LoadTextureFromImage(image);
  18. }
  19. public override void Draw(Smoll.Layer.DrawMode drawMode) {
  20. if(drawMode == Layer.DrawMode.Normal) {
  21. ownerTransform ??= owner.GetComponent<Transform2DComponent>();
  22. ownerTransform ??= new Transform2DComponent();
  23. var tr = ownerTransform.AbsoluteTransform();
  24. Raylib.DrawTextureEx(texture, new Vector2((float)tr.position.Real, (float)tr.position.Imaginary), tr.angle*180f/MathF.PI, tr.scale, Color.White);
  25. }
  26. }
  27. public void Dispose()
  28. {
  29. Raylib.UnloadTexture(texture);
  30. }
  31. }
  32. }