/// <summary> /// Draws the specified rectangle. /// </summary> /// <param name="rectangle">The rectangle.</param> /// <param name="id">The identifier.</param> public void Draw(IReadOnlyBox2D rectangle, uint id) { var texCoords = SpriteSheet.CalcSpriteTexCoords(id); Texture.Activate(); rectangle.DrawTexturedRect(texCoords); Texture.Deactivate(); }
/// <summary> /// draws a GL quad, textured with an animation. /// </summary> /// <param name="rectangle">coordinates ofthe GL quad</param> /// <param name="totalSeconds">animation position in seconds</param> public void Draw(IReadOnlyBox2D rectangle, float totalSeconds) { var id = CalcAnimationSpriteID(FromID, ToID, AnimationLength, totalSeconds); var texCoords = SpriteSheet.CalcSpriteTexCoords(id); SpriteSheet.Activate(); rectangle.DrawTexturedRect(texCoords); SpriteSheet.Deactivate(); }
public TileMap() { var map = new TmxMap($@"{Path.GetDirectoryName(PathTools.GetSourceFilePath())}\content\grass.tmx"); var tileSize = new Vector2(1f / (map.Width - 1), 1f / (map.Height - 1)); var tileSet = map.Tilesets[0]; SpriteSheetName = Path.GetFileName(tileSet.Image.Source); var columns = (uint)tileSet.Columns.Value; var rows = (uint)(tileSet.TileCount.Value / tileSet.Columns.Value); foreach (var tile in map.Layers[0].Tiles) { if (0 == tile.Gid) { continue; } var x = tile.X / (float)map.Width; var y = (map.Height - tile.Y - 1) / (float)map.Height; var geom = new Box2D(x, y, tileSize.X, tileSize.Y); var tex = SpriteSheet.CalcSpriteTexCoords((uint)tile.Gid - 1, columns, rows); tiles.Add(new Tile(geom, tex)); } }
private List <Block> LoadComponent(int gridX, int gridY, String type) { float x = TransformPositionRelative(gridX); float y = TransformPositionRelative(gridY); List <Block> blocks = new List <Block>(); Block block = null; uint typeUint = stringToUint(type) - 1; switch (type) { case TiledObjectCodes.EMPTY_SPACE: block = new Block(BlockType.EMPTY, "map", spriteSheetMap.CalcSpriteTexCoords(typeUint), squareSize, x, y, false); break; case TiledObjectCodes.ENEMY: block = new Block(BlockType.ENEMY, "char", spriteSheetChar.CalcSpriteTexCoords(typeUint), squareSize / 1.1f, x, y); break; case TiledObjectCodes.PLAYER: block = new Block(BlockType.PLAYER, "char", spriteSheetChar.CalcSpriteTexCoords(typeUint), squareSize / 1.1f, x, y); break; case TiledObjectCodes.PORTAL: block = new Block(BlockType.PORTAL, "char", spriteSheetChar.CalcSpriteTexCoords(typeUint), squareSize, x, y, false); break; case TiledObjectCodes.GROUND_WITH_GRASS: block = new Block(BlockType.GROUND, "map", spriteSheetMap.CalcSpriteTexCoords(typeUint), squareSize, x, y); break; case TiledObjectCodes.DIRT: block = new Block(BlockType.GROUND, "map", spriteSheetMap.CalcSpriteTexCoords(typeUint), squareSize, x, y); break; case TiledObjectCodes.OBSTACLE: block = new Block(BlockType.OBSTACLE, "map", spriteSheetMap.CalcSpriteTexCoords(typeUint), squareSize, x, y); break; case TiledObjectCodes.INVISIBLE_ENEMY_BARRIER: block = new Block(BlockType.INVISIBLE_ENEMY_BARRIER, "map", spriteSheetMap.CalcSpriteTexCoords(typeUint), squareSize, x, y); block.IsVisible = false; break; case TiledObjectCodes.BOMB_ITEM: block = new Block(BlockType.ITEM, "char", spriteSheetChar.CalcSpriteTexCoords(typeUint), squareSize, x, y); break; } if (block == null) { block = new Block(BlockType.EMPTY, "map", null, squareSize, x, y, false); } blocks.Add(block); return(blocks); }