Пример #1
0
        public static TileResourceCollection FromXmlProxy(LibraryX.TilePoolX proxy, TilePool pool, ITexturePool texturePool)
        {
            if (proxy == null)
            {
                return(null);
            }

            TileResourceCollection collection = new TileResourceCollection(proxy.TileWidth, proxy.TileHeight, pool, texturePool);

            texturePool.RemoveResource(collection.TextureId);

            collection._tileSource = texturePool.GetResource(proxy.Texture);

            if (collection._tileSource != null)
            {
                collection._tileSource.Apply(c => {
                    return((c.A == 0) ? Colors.Transparent : c);
                });
            }

            if (proxy.TileDefinitions != null)
            {
                foreach (var tiledef in proxy.TileDefinitions)
                {
                    TileResourceCollection.FromXmlProxy(tiledef, collection);
                }
            }

            if (collection.TextureResource != null)
            {
                collection.RecalculateOpenLocations();
            }

            return(collection);
        }
Пример #2
0
        private void ExpandTexture()
        {
            int width  = _tileSource.Width;
            int height = _tileSource.Height;

            if (width == height)
            {
                width *= 2;
            }
            else
            {
                height *= 2;
            }

            TextureResource newTex = new TextureResource(width, height);

            newTex.Set(_tileSource, new Point(0, 0));

            int factorX = newTex.Width / TileWidth;
            int factorY = newTex.Height / TileHeight;
            int threshX = _tileSource.Width / TileWidth;
            int threshY = _tileSource.Height / TileHeight;

            for (int y = 0; y < factorY; y++)
            {
                for (int x = 0; x < factorX; x++)
                {
                    if (x >= threshX || y >= threshY)
                    {
                        _openLocations.Add(new TileCoord(x, y));
                    }
                }
            }

            _texturePool.RemoveResource(_tileSource.Uid);
            _tileSource = newTex;
            _texturePool.AddResource(_tileSource);
        }