diff --git a/RayGame/Renderers.cs b/RayGame/Renderers.cs index 57c769c..aea9a67 100644 --- a/RayGame/Renderers.cs +++ b/RayGame/Renderers.cs @@ -76,15 +76,14 @@ public class SpriteRenderer : IRenderer /// public GameObject Container { get; set; } - private Texture2D sprite; - - private Rectangle source; - + // private Texture2D sprite; + private List<(Rectangle,Sprite)> SpriteList; + private int SpriteIndex; private Rectangle destination; - private Vector2 Origin; - public Transform transform; + private (Rectangle ,Sprite) SelectedSprite; + // private Texture2D spritesheet; /// /// Initializes the renderer. This method is called when the renderer is first added to a . @@ -93,26 +92,35 @@ public void Start() { transform = new Transform(); destination = new Rectangle(); + SpriteList = new(); + SpriteIndex = 0; + } + + public Sprite GetSprite(int SIndex) + { + return SpriteList[SIndex].Item2; } - /// - /// Retrieves the current sprite texture. - /// - /// The current sprite. - public Texture2D GetSprite() + public void SetIndex(int i) { - return sprite; + if (i < SpriteList.Count) + { + SpriteIndex = i; + } } - - /// - /// Sets the sprite texture. - /// - /// The new sprite to set. - public void SetSprite(Texture2D ImputSprite) + + public void ChangeIndex(int i) { - sprite = ImputSprite; - source = new Rectangle(0, 0, sprite.Width, sprite.Height); - + if (SpriteIndex + i < SpriteList.Count) + { + SpriteIndex += i; + } + } + + public void AddSprite(Sprite InputSprite) + { + Rectangle src = new Rectangle(0,0,InputSprite.Image.Width,InputSprite.Image.Height); + SpriteList.Add(new (src,InputSprite)); } /// @@ -120,12 +128,15 @@ public void SetSprite(Texture2D ImputSprite) /// public void Update() { + SelectedSprite = SpriteList[SpriteIndex]; + + destination.Position = Container.Transform.Position + transform.Position; - destination.Width = sprite.Width * (Container.Transform.Scale * transform.Scale); - destination.Height = sprite.Height * (Container.Transform.Scale* transform.Scale); + destination.Width = SelectedSprite.Item2.Image.Width * (Container.Transform.Scale * transform.Scale); + destination.Height = SelectedSprite.Item2.Image.Height * (Container.Transform.Scale* transform.Scale); Origin = new Vector2(destination.Width / 2, destination.Height / 2); - Raylib.DrawTexturePro(sprite,source,destination,Origin, Container.Transform.GetRotation() + transform.GetRotation(),Color.White); + Raylib.DrawTexturePro(SelectedSprite.Item2.Image,SelectedSprite.Item1,destination,Origin, Container.Transform.GetRotation() + transform.GetRotation(),Color.White); Console.WriteLine(destination); } } \ No newline at end of file diff --git a/RayGame/Resources.cs b/RayGame/Resources.cs new file mode 100644 index 0000000..da4d7bb --- /dev/null +++ b/RayGame/Resources.cs @@ -0,0 +1,30 @@ +using Raylib_cs; + +namespace RayGame; + +public class Resources +{ + +} + +public class Sprite +{ + public Texture2D Image; + + public Sprite(string TextureName) + { + try + { + var I = Raylib.LoadImage($"/Resources/{TextureName}"); + Image = Raylib.LoadTextureFromImage(I); + Raylib.UnloadImage(I); + } + catch (Exception e) + { + Console.WriteLine("Image does not Exist"); + throw; + } + } + + +} \ No newline at end of file diff --git a/RayGame/bin/Debug/RayGame.xml b/RayGame/bin/Debug/RayGame.xml index 5e4774a..1cd4711 100644 --- a/RayGame/bin/Debug/RayGame.xml +++ b/RayGame/bin/Debug/RayGame.xml @@ -532,5 +532,20 @@ The color to use for rendering the lines. + + + The Container is the reference to the it is connected to. + + + + + Initializes the renderer. This method is called when the renderer is first added to a . + + + + + Updates the renderer. This method is called once per frame. + + diff --git a/RayGame/bin/Debug/net7.0/RayGame.dll b/RayGame/bin/Debug/net7.0/RayGame.dll index 7679ed3..afb65b7 100644 Binary files a/RayGame/bin/Debug/net7.0/RayGame.dll and b/RayGame/bin/Debug/net7.0/RayGame.dll differ diff --git a/RayGame/bin/Debug/net7.0/RayGame.pdb b/RayGame/bin/Debug/net7.0/RayGame.pdb index be0d596..6af42d6 100644 Binary files a/RayGame/bin/Debug/net7.0/RayGame.pdb and b/RayGame/bin/Debug/net7.0/RayGame.pdb differ diff --git a/RayGame/bin/Debug/net7.0/RayGame.xml b/RayGame/bin/Debug/net7.0/RayGame.xml index 5e4774a..1cd4711 100644 --- a/RayGame/bin/Debug/net7.0/RayGame.xml +++ b/RayGame/bin/Debug/net7.0/RayGame.xml @@ -532,5 +532,20 @@ The color to use for rendering the lines. + + + The Container is the reference to the it is connected to. + + + + + Initializes the renderer. This method is called when the renderer is first added to a . + + + + + Updates the renderer. This method is called once per frame. + + diff --git a/RayGame/obj/Debug/net7.0/RayGame.csproj.CoreCompileInputs.cache b/RayGame/obj/Debug/net7.0/RayGame.csproj.CoreCompileInputs.cache index 51fa1ee..c65b6cc 100644 --- a/RayGame/obj/Debug/net7.0/RayGame.csproj.CoreCompileInputs.cache +++ b/RayGame/obj/Debug/net7.0/RayGame.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -b3f94a3005f13e86a2b5d6ee29bad87c0808b77f +ee154ba413beb2ea85b29ee1976f6fa3aaeae069 diff --git a/RayGame/obj/Debug/net7.0/RayGame.csproj.FileListAbsolute.txt b/RayGame/obj/Debug/net7.0/RayGame.csproj.FileListAbsolute.txt index 3d839e7..a7047f7 100644 --- a/RayGame/obj/Debug/net7.0/RayGame.csproj.FileListAbsolute.txt +++ b/RayGame/obj/Debug/net7.0/RayGame.csproj.FileListAbsolute.txt @@ -20,5 +20,4 @@ C:\Users\dhruv\RiderProjects\RayGame\RayGame\bin\Debug\net7.0\runtimes\win-x64\n C:\Users\dhruv\RiderProjects\RayGame\RayGame\bin\Debug\net7.0\runtimes\win-x86\native\raylib.dll C:\Users\dhruv\RiderProjects\RayGame\RayGame\obj\Debug\net7.0\RayGame.csproj.AssemblyReference.cache C:\Users\dhruv\RiderProjects\RayGame\RayGame\obj\Debug\net7.0\RayGame.csproj.CopyComplete -C:\Users\dhruv\RiderProjects\RayGame\RayGame\bin\Debug\net7.0\Demo\test.png C:\Users\dhruv\RiderProjects\RayGame\RayGame\bin\Debug\net7.0\RayGame.xml diff --git a/RayGame/obj/Debug/net7.0/RayGame.dll b/RayGame/obj/Debug/net7.0/RayGame.dll index 7679ed3..afb65b7 100644 Binary files a/RayGame/obj/Debug/net7.0/RayGame.dll and b/RayGame/obj/Debug/net7.0/RayGame.dll differ diff --git a/RayGame/obj/Debug/net7.0/RayGame.pdb b/RayGame/obj/Debug/net7.0/RayGame.pdb index be0d596..6af42d6 100644 Binary files a/RayGame/obj/Debug/net7.0/RayGame.pdb and b/RayGame/obj/Debug/net7.0/RayGame.pdb differ diff --git a/RayGame/obj/Debug/net7.0/ref/RayGame.dll b/RayGame/obj/Debug/net7.0/ref/RayGame.dll index 2c41e9f..2261816 100644 Binary files a/RayGame/obj/Debug/net7.0/ref/RayGame.dll and b/RayGame/obj/Debug/net7.0/ref/RayGame.dll differ diff --git a/RayGame/obj/Debug/net7.0/refint/RayGame.dll b/RayGame/obj/Debug/net7.0/refint/RayGame.dll index 2c41e9f..2261816 100644 Binary files a/RayGame/obj/Debug/net7.0/refint/RayGame.dll and b/RayGame/obj/Debug/net7.0/refint/RayGame.dll differ