internal void DrawTexture(TextureInfo texture, float xPos, float yPos, float zPos, float rotation, float texLeft, float texTop, float texRight, float texBottom, float width, float height) { Bindings.DrawTexture2D( (uint)texture.Reference, xPos, yPos, zPos, rotation, texLeft, texTop, texRight, texBottom, width, height); }
public void DrawSprite(IDisplayable displayable, TextureInfo texture, int cell) { var drawInfo = displayable.DrawInfo; if (displayable == null || texture == null || !drawInfo.Visible) { return; } Texture2D xnaTec = GetTexture(texture.ID); XNAColor color = XNAColor.White; int drawIndex = 0; var topLeft = GetScreenPoint(displayable); XNARec src = GetTextureCell(texture, cell); XNARec dest = new XNARec((int)topLeft.X, (int)topLeft.Y, src.Width, src.Height); Rectangle dest1 = new Rectangle(topLeft.X, topLeft.Y, displayable.Position.Width, displayable.Position.Height); Rectangle dest2 = new Rectangle(0, 0, src.Width, src.Height); switch (texture.AnchorOrigin) { case AnchorOrigin.BottomCenter: dest2.BottomCenter = dest1.BottomCenter; break; case AnchorOrigin.Center: dest2.Center = dest1.Center; break; default: throw new NotImplementedException(); } if (texture.CellAnchorOffset != null) { dest2.Translate(texture.CellAnchorOffset.Value.Flip(drawInfo.FlipX, drawInfo.FlipY)); } var dest3 = new XNARec((int)dest2.Left, (int)dest2.Top, (int)dest2.Width, (int)dest2.Height); SpriteEffects flip = SpriteEffects.None; if (!drawInfo.FlipOffsetsOnly) { if (drawInfo.FlipX) { flip = flip | SpriteEffects.FlipHorizontally; } if (drawInfo.FlipY) { flip = flip | SpriteEffects.FlipVertically; } } spriteBatch.Draw(xnaTec, dest3, src, color, 0, Vector2.Zero, flip, 0); drawIndex++; }
public static void Unload(TextureInfo texture) { Bindings.UnloadTexture((uint)texture.Reference); }
private XNARec GetTextureCell(TextureInfo texture, int cell) { Vector2 xy = cell.ToXY(texture.Columns).Scale(texture.CellSize); return(new XNARec((int)(texture.Origin.X + xy.X), (int)(texture.Origin.Y + xy.Y), (int)texture.CellSize.X, (int)texture.CellSize.Y)); }