public static TileGrid Create(Rectangle viewport, Texture2D texture, int numTilesX, int numTilesY, float heightScale, Vector2? worldOffset, Vector2 cameraOffset) { var tileWidth = texture.Width; var tileHeight = texture.Height; var spriteSheet = new SpriteSheet(texture); spriteSheet.AddSourceSprite(1, new Rectangle(0, 0, tileWidth, tileHeight)); if (worldOffset == null) { var worldOffsetX = -viewport.Width / 2; var worldOffsetY = -viewport.Height / 2; worldOffset = new Vector2(worldOffsetX, worldOffsetY); } var tileGrid = new TileGrid(tileWidth, tileHeight, numTilesX, numTilesY, worldOffset.Value, cameraOffset, spriteSheet, viewport) { TileScale = heightScale }; for (int i = 0; i < numTilesX; i++) { for (int j = 0; j < numTilesY; j++) { tileGrid.SetTile(i, j, 1); } } return tileGrid; }
public Button (Vector2 position, Vector2 size, Texture2D texture) { _position = position; _size = size; _center = position + size / 2f; _spriteSheet = new SpriteSheet (texture); var columns = 3; var padding = 1; var spriteSizeY = texture.Height; var spriteSizeX = (texture.Width - padding * (columns - 1)) / columns; for (int x = 0; x < columns; x++) { int left = (int)(x * (spriteSizeX + padding)); int top = 0; _spriteSheet.AddSourceSprite(x, new Rectangle(left, top, spriteSizeX, spriteSizeY)); } _textureScale = _size.X / SourceRectangle.Width; }