public Sprites() { Gfx = new Bitmap("gfx.png"); Bonus = new SpriteSource[8]; for (int i = 0; i < 8; i++) { Bonus[i] = new SpriteSource(i * 2, 10, 2); } }
/// <summary> /// Render a sprite onto the specified buffer /// </summary> /// <param name="g"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="source"></param> private void RenderSprite(Graphics g, decimal x, decimal y, SpriteSource source) { var size = PixelGrid * source.Size; var pixelX = (int)((x + 0.5m - source.Size * 0.5m) * PixelGrid); var pixelY = (int)((y + 0.5m - source.Size * 0.5m) * PixelGrid); g.DrawImage(Gfx, new Rectangle(pixelX, pixelY, size, size), PixelGrid * source.XPos, PixelGrid * source.YPos, size, size, GraphicsUnit.Pixel); }
/// <summary> /// Render a sprite to the graphics context /// Position is top corner of 8 pixel grid /// Larger sprites (eg. PacMac, Ghosts) are offset so they are in the centre of the square /// </summary> /// <param name="g"></param> /// <param name="x">Screen X (pixel)</param> /// <param name="y">Screen Y (pixel)</param> /// <param name="size">Size of sprite on screen (pixel)</param> /// <param name="source">Sprite to show</param> public void RenderSprite(Graphics g, int x, int y, SpriteSource source) { var size = PixelGrid * source.Size; x = x + PixelGrid / 2 - size / 2; y = y + PixelGrid / 2 - size / 2; g.DrawImage(Gfx, new Rectangle(x, y, size, size), PixelGrid * source.XPos, PixelGrid * source.YPos, size, size, GraphicsUnit.Pixel); }