예제 #1
0
        /// <summary>
        /// Set a tile to a specific tile from the source texture.
        /// </summary>
        /// <param name="tileX">The tile's X position on the map.</param>
        /// <param name="tileY">The tile's Y position on the map.</param>
        /// <param name="sourceX">The source X position from the tile map in pixels.</param>
        /// <param name="sourceY">The source Y position from the tile map in pixels.</param>
        /// <param name="layer">The tile's layer.</param>
        /// <returns>The TileInfo for the altered tile.</returns>
        public TileInfo SetTile(int tileX, int tileY, int sourceX, int sourceY, string layer = "") {
            sourceX += TextureLeft;
            sourceY += TextureTop;

            if (layer == "") layer = DefaultLayerName;

            // Clear the tile there first so tiles do not stack.
            ClearTile(tileX, tileY, layer);

            // Update arguments after calling other tile methods.
            if (!UsePositions) {
                tileX *= TileWidth;
                tileY *= TileHeight;
            }

            tileX = (int)Util.Clamp(tileX, 0, Width - TileWidth);
            tileY = (int)Util.Clamp(tileY, 0, Height - TileHeight);

            var t = new TileInfo(tileX, tileY, sourceX, sourceY, TileWidth, TileHeight);
            TileLayers[layerNames[layer]].Add(t);

            RegisterTile(tileX, tileY, layerNames[layer], t);

            NeedsUpdate = true;

            return t;
        }
예제 #2
0
 void RegisterTile(int x, int y, int layer, TileInfo tile) {
     if (!tileTable.ContainsKey(layer)) {
         tileTable.Add(layer, new Dictionary<int, Dictionary<int, TileInfo>>());
     }
     if (!tileTable[layer].ContainsKey(x)) {
         tileTable[layer].Add(x, new Dictionary<int, TileInfo>());
     }
     tileTable[layer][x].Add(y, tile);
 }
예제 #3
0
        /// <summary>
        /// Set a tile to a specific color.
        /// </summary>
        /// <param name="tileX">The tile's x position on the map.</param>
        /// <param name="tileY">The tile's y position on the map.</param>
        /// <param name="color">The tile's color.</param>
        /// <param name="layer">The tile's layer.</param>
        /// <returns>The TileInfo of the altered tile.</returns>
        public TileInfo SetTile(int tileX, int tileY, Color color, string layer = "") {
            if (layer == "") layer = DefaultLayerName;

            // Clear the tile there first so tiles do not stack.
            ClearTile(tileX, tileY, layer);

            // Update arguments after calling other tile methods.
            if (!UsePositions) {
                tileX *= TileWidth;
                tileY *= TileHeight;
            }

            // Clamp tile inside tilemap.
            tileX = (int)Util.Clamp(tileX, 0, Width - TileWidth);
            tileY = (int)Util.Clamp(tileY, 0, Height - TileHeight);

            var t = new TileInfo(tileX, tileY, -1, -1, TileWidth, TileHeight, color);
            TileLayers[layerNames[layer]].Add(t);

            // Register tile for look ups.
            RegisterTile(tileX, tileY, layerNames[layer], t);

            NeedsUpdate = true;

            return t;
        }
예제 #4
0
 /// <summary>
 /// Get the index of a specific tile on the source Texture.
 /// </summary>
 /// <param name="tile">The tile to get the index of.</param>
 /// <returns>The index of the tile.</returns>
 public int GetTileIndex(TileInfo tile) {
     return tile.GetIndex(this);
 }