public static SpriteboxJson ToJsonElement(Spritebox spriteBox) { if (spriteBox == null) { return(null); } SpriteboxJson sprBoxJson = new SpriteboxJson() { posX = spriteBox.GetPosition().X, posY = spriteBox.GetPosition().Y, width = spriteBox.GetWidth(), height = spriteBox.GetHeight(), rotation = spriteBox._rotation, sourceHeight = spriteBox.GetSourceRectangle().Height, sourceWidth = spriteBox.GetSourceRectangle().Width, sourceX = spriteBox.GetSourceRectangle().X, sourceY = spriteBox.GetSourceRectangle().Y, textureKey = spriteBox.GetTextureKey(), layer = spriteBox.GetLayer(), visible = spriteBox.Visible() }; return(sprBoxJson); }
/// <summary> /// Overridable, allows us to control how to draw this object directly. /// Not recommended if you can achieve your goal with more higher level methods. /// </summary> /// <param name="device"></param> /// <param name="spriteBatch"></param> public virtual void Draw(GraphicsDevice device, SpriteBatch spriteBatch) { var orderedSprites = SpriteBoxes.OrderBy(f => f.Value.GetLayer()).ToList(); foreach (KeyValuePair <string, Spritebox> pair in orderedSprites) { Spritebox spriteBox = pair.Value; if (spriteBatch != null && ContentManager.GetTexture(spriteBox.GetTextureKey()) != null && spriteBox.Visible()) { spriteBatch.Draw(ContentManager.GetTexture(spriteBox.GetTextureKey()), new Rectangle((int)(spriteBox.GetPosition().X + GetPosition().X), (int)(spriteBox.GetPosition().Y + GetPosition().Y), spriteBox.GetWidth(), spriteBox.GetHeight()), spriteBox.GetSourceRectangle(), Color.White); } } // Draw children foreach (Drawable d in _children) { d.Draw(device, spriteBatch); } }