A Smoll game engine
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

30 wiersze
1.2 KiB

  1. using System.Numerics;
  2. using Raylib_cs;
  3. namespace Smoll.Ex2 {
  4. class SpriteComponent : Smoll.Component {
  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. texture = owner.layers.First().attachedEngine.GetModule<RaylibAssetManagerModule>().GetTexture(asset_name);
  17. }
  18. public override void Draw(Smoll.Layer.DrawMode drawMode) {
  19. if(drawMode == Layer.DrawMode.Normal) {
  20. ownerTransform ??= owner.GetComponent<Transform2DComponent>();
  21. ownerTransform ??= new Transform2DComponent();
  22. var tr = ownerTransform.AbsoluteTransform();
  23. Raylib.DrawTextureEx(texture, new Vector2((float)tr.position.Real, (float)tr.position.Imaginary), tr.angle*180f/MathF.PI, tr.scale, Color.White);
  24. }
  25. }
  26. }
  27. }