internal TiledMapTilesetTileAnimationFrame(TiledMapTileset tileset, int localTileIdentifier, int durationInMilliseconds) { LocalTileIdentifier = localTileIdentifier; Duration = new TimeSpan(0, 0, 0, 0, durationInMilliseconds); TextureCoordinates = new Vector2[4]; CreateTextureCoordinates(tileset); }
public TiledMapTileObject(int identifier, string name, TiledMapTileset tileset, TiledMapTilesetTile tile, SizeF size, Vector2 position, float rotation = 0, float opacity = 1, bool isVisible = true, string type = null) : base(identifier, name, size, position, rotation, opacity, isVisible, type) { Tileset = tileset; Tile = tile; }
private static void ReadTilesets(ContentReader input, TiledMap map) { var tilesetCount = input.ReadInt32(); for (var i = 0; i < tilesetCount; i++) { var tileset = new TiledMapTileset(input); map.AddTileset(tileset); } }
public TiledMapTileObject(ContentReader input, TiledMap map) : base(input) { var globalTileIdentifierWithFlags = input.ReadUInt32(); var tile = new TiledMapTile(globalTileIdentifierWithFlags); Tileset = map.GetTilesetByTileGlobalIdentifier(tile.GlobalIdentifier); var localTileIdentifier = tile.GlobalIdentifier - Tileset.FirstGlobalIdentifier; TilesetTile = Tileset.Tiles.FirstOrDefault(x => x.LocalTileIdentifier == localTileIdentifier); }
internal TiledMapTilesetAnimatedTile(TiledMapTileset tileset, ContentReader input, int localTileIdentifier, int animationFramesCount) : base(localTileIdentifier, input) { AnimationFrames = new ReadOnlyCollection <TiledMapTilesetTileAnimationFrame>(_animationFrames); _timer = TimeSpan.Zero; for (var i = 0; i < animationFramesCount; i++) { var localTileIdentifierForFrame = input.ReadInt32(); var frameDurationInMilliseconds = input.ReadInt32(); var tileSetTileFrame = new TiledMapTilesetTileAnimationFrame(tileset, localTileIdentifierForFrame, frameDurationInMilliseconds); _animationFrames.Add(tileSetTileFrame); CurrentAnimationFrame = AnimationFrames[0]; } }
private void CreateTextureCoordinates(TiledMapTileset tileset) { var sourceRectangle = tileset.GetTileRegion(LocalTileIdentifier); var texture = tileset.Texture; var texelLeft = sourceRectangle.X / texture.Width; var texelTop = sourceRectangle.Y / texture.Height; var texelRight = (sourceRectangle.X + sourceRectangle.Width) / (float)texture.Width; var texelBottom = (sourceRectangle.Y + sourceRectangle.Height) / (float)texture.Height; TextureCoordinates[0].X = texelLeft; TextureCoordinates[0].Y = texelTop; TextureCoordinates[1].X = texelRight; TextureCoordinates[1].Y = texelTop; TextureCoordinates[2].X = texelLeft; TextureCoordinates[2].Y = texelBottom; TextureCoordinates[3].X = texelRight; TextureCoordinates[3].Y = texelBottom; }
internal void AddTileset(TiledMapTileset tileset) { _tilesets.Add(tileset); }
public void AddTileset(TiledMapTileset tileset, int firstGlobalIdentifier) { _tilesets.Add(tileset); _firstGlobalIdentifiers.Add(new Tuple <TiledMapTileset, int>(tileset, firstGlobalIdentifier)); }
public int GetTilesetFirstGlobalIdentifier(TiledMapTileset tileset) { return(_firstGlobalIdentifiers.FirstOrDefault(t => t.Item1 == tileset).Item2); }