From ed9ebec2b6901210fcc15c2735820f7c77b416cd Mon Sep 17 00:00:00 2001 From: Dylan Wilson Date: Tue, 18 Aug 2015 22:58:37 +1000 Subject: [PATCH] got the sprite code compiling and i can see the stump --- .../MonoGame.Extended.csproj | 5 +-- Source/MonoGame.Extended/Sprites/Sprite.cs | 9 ++---- .../Sprites/SpriteBatchExtensions.cs | 13 ++++++++ Source/Sandbox/SandboxGame.cs | 31 +++++++++---------- 4 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 Source/MonoGame.Extended/Sprites/SpriteBatchExtensions.cs diff --git a/Source/MonoGame.Extended/MonoGame.Extended.csproj b/Source/MonoGame.Extended/MonoGame.Extended.csproj index 1cbe7b6f..3e28164d 100644 --- a/Source/MonoGame.Extended/MonoGame.Extended.csproj +++ b/Source/MonoGame.Extended/MonoGame.Extended.csproj @@ -47,10 +47,11 @@ + - + @@ -86,4 +87,4 @@ <<<<<<< HEAD --> - + \ No newline at end of file diff --git a/Source/MonoGame.Extended/Sprites/Sprite.cs b/Source/MonoGame.Extended/Sprites/Sprite.cs index 7715da8b..56213c6f 100644 --- a/Source/MonoGame.Extended/Sprites/Sprite.cs +++ b/Source/MonoGame.Extended/Sprites/Sprite.cs @@ -1,16 +1,12 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using MonoGame.Extended.Graphics; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using MonoGame.Extended.TextureAtlases; namespace MonoGame.Extended.Sprites { public class Sprite { - public TextureRegion2D TextureRegion; + public TextureRegion2D TextureRegion { get; set; } public Color Color { get; set; } public bool IsVisible { get; set; } @@ -23,6 +19,7 @@ namespace MonoGame.Extended.Sprites { TextureRegion = new TextureRegion2D(texture); Scale = Vector2.One; + Color = Color.White; IsVisible = true; } diff --git a/Source/MonoGame.Extended/Sprites/SpriteBatchExtensions.cs b/Source/MonoGame.Extended/Sprites/SpriteBatchExtensions.cs new file mode 100644 index 00000000..fe97658c --- /dev/null +++ b/Source/MonoGame.Extended/Sprites/SpriteBatchExtensions.cs @@ -0,0 +1,13 @@ +using Microsoft.Xna.Framework.Graphics; + +namespace MonoGame.Extended.Sprites +{ + public static class SpriteBatchExtensions + { + public static void Draw(this SpriteBatch spriteBatch, Sprite sprite) + { + if (sprite.IsVisible) + spriteBatch.Draw(sprite.TextureRegion.Texture, null, sprite.GetBoundingRectangle(), sprite.TextureRegion.Bounds, sprite.Origin, sprite.Rotation, sprite.Scale, sprite.Color); + } + } +} \ No newline at end of file diff --git a/Source/Sandbox/SandboxGame.cs b/Source/Sandbox/SandboxGame.cs index b9a3aa05..dfea9758 100644 --- a/Source/Sandbox/SandboxGame.cs +++ b/Source/Sandbox/SandboxGame.cs @@ -1,14 +1,11 @@ -using Microsoft.Xna.Framework; +using System.Diagnostics; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using MonoGame.Extended; using MonoGame.Extended.BitmapFonts; -<<<<<<< HEAD -using MonoGame.Extended.Graphics; -using MonoGame.Extended.Sprites; -using System.Diagnostics; -using System; using MonoGame.Extended.Maps.Tiled; +using MonoGame.Extended.Sprites; using MonoGame.Extended.ViewportAdapters; namespace Sandbox @@ -140,18 +137,18 @@ namespace Sandbox //_spriteBatch.Draw(_backgroundTexture, new Rectangle(0, 0, _tiledMap.WidthInPixels, _tiledMap.HeightInPixels), Color.White); //_spriteBatch.End(); - _tiledMap.Draw(_camera); + //_tiledMap.Draw(_camera); - _spriteBatch.Begin(); - _spriteBatch.DrawString(_bitmapFont, "This is MonoGame.Extended", new Vector2(50, 50), new Color(Color.Black, 0.5f)); - _spriteBatch.DrawString(_bitmapFont, string.Format("Camera: {0}", _camera.Position), new Vector2(50, 100), Color.Black); - //_spriteBatch.DrawString(_bitmapFont, - // "Contrary to popular belief, Lorem Ipsum is not simply random text.\n\n" + - // "It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard " + - // "McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin " + - // "words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, " + - // "discovered the undoubtable source.", new Vector2(50, 100), new Color(Color.Black, 0.5f), _viewportAdapter.VirtualWidth - 50); - _spriteBatch.End(); + //_spriteBatch.Begin(); + //_spriteBatch.DrawString(_bitmapFont, "This is MonoGame.Extended", new Vector2(50, 50), new Color(Color.Black, 0.5f)); + //_spriteBatch.DrawString(_bitmapFont, string.Format("Camera: {0}", _camera.Position), new Vector2(50, 100), Color.Black); + ////_spriteBatch.DrawString(_bitmapFont, + //// "Contrary to popular belief, Lorem Ipsum is not simply random text.\n\n" + + //// "It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard " + + //// "McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin " + + //// "words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, " + + //// "discovered the undoubtable source.", new Vector2(50, 100), new Color(Color.Black, 0.5f), _viewportAdapter.VirtualWidth - 50); + //_spriteBatch.End(); _spriteBatch.Begin(transformMatrix: _camera.GetViewMatrix()); //Console.WriteLine(_stumpSprite.Position);