public virtual Dictionary <string, Sprite> GetSpriteBoxes() { if (CurrentAnimation == null || CurrentAnimation.GetCurrentSprite() == null) { return(new Dictionary <string, Sprite>()); } return(FromJsonSprites(CurrentAnimation.GetCurrentSprite())); }
public override void Draw(GraphicsDevice device, SpriteBatch spriteBatch, GameInfo info) { if (CurrentAnimation != null && CurrentAnimation.GetCurrentSprite() != null && Visible) { var orderedSprites = GetSpriteBoxes().OrderBy(f => f.Value.GetLayer()).ToList(); foreach (KeyValuePair <string, Sprite> pair in orderedSprites) { Sprite spriteBox = pair.Value; if (spriteBatch != null && ContentLoader.GetTexture(spriteBox.GetTextureKey(), device) != null && spriteBox.Visible()) { spriteBatch.Draw(ContentLoader.GetTexture(spriteBox.GetTextureKey(), device), new Rectangle((int)(spriteBox.GetPosition().X + GetPosition().X), (int)(spriteBox.GetPosition().Y + GetPosition().Y), spriteBox.GetWidth(), spriteBox.GetHeight()), spriteBox.GetSourceRectangle(), Color.White); } } } base.Draw(device, spriteBatch, info); }
public virtual Rectangle GetBoundingBox() { if (CurrentAnimation == null || CurrentAnimation.GetCurrentSprite() == null) { return(BoundingBox); } else { int lowestX = 0; int lowestY = 0; int highestX = 0; int highestY = 0; foreach (KeyValuePair <string, Sprite> pair in FromJsonSprites(CurrentAnimation.GetCurrentSprite())) { if (pair.Value.GetPosition().X < lowestX) { lowestX = (int)pair.Value.GetPosition().X; } if (pair.Value.GetPosition().Y < lowestY) { lowestY = (int)pair.Value.GetPosition().Y; } if (pair.Value.GetRectangle().Right > highestX) { highestX = pair.Value.GetRectangle().Right; } if (pair.Value.GetRectangle().Bottom > highestY) { highestY = pair.Value.GetRectangle().Bottom; } } return(new Rectangle(lowestX + (int)GetPosition().X, lowestY + (int)GetPosition().Y, highestX - lowestX, highestY - lowestY)); } }