using System.Numerics; using Raylib_cs; namespace Smoll.Ex2 { class SpriteComponent : Smoll.Component { Complex offset; string asset_name; Transform2DComponent? ownerTransform; Texture2D texture; public SpriteComponent(string asset_name, int offset_x = 0, int offset_y = 0) { this.offset = offset_x + Complex.ImaginaryOne*offset_y; this.asset_name = asset_name; } public override void OnAttached() { ownerTransform = owner.GetComponent(); texture = owner.layers.First().attachedEngine.GetModule().GetTexture(asset_name); } public override void Draw(Smoll.Layer.DrawMode drawMode) { if(drawMode == Layer.DrawMode.Normal) { ownerTransform ??= owner.GetComponent(); ownerTransform ??= new Transform2DComponent(); var tr = ownerTransform.AbsoluteTransform(); Raylib.DrawTextureEx(texture, new Vector2((float)tr.position.Real, (float)tr.position.Imaginary), tr.angle*180f/MathF.PI, tr.scale, Color.White); } } } }