Example #1
0
        public TileSet(Texture2D texture, Texture2D maskTexture, int graphicsTileSize)
        {
            this.sw = texture.Width / graphicsTileSize;
            this.sh = texture.Height / graphicsTileSize;

            tiles = new Tile[sw * sh];

            this.gTileSize = graphicsTileSize;
            this.texture   = texture;

            for (int y = 0; y < sh; y++)
            {
                for (int x = 0; x < sw; x++)
                {
                    tiles[x + y * sw] = new Tile(new TextureSource(texture, new Rectangle(x * gTileSize, y * gTileSize, gTileSize, gTileSize)),
                                                 TileMask.FromTexture(maskTexture, x * TileSize, y * TileSize));
                }
            }
        }
Example #2
0
        public static TileMask FromTexture(Texture2D texture, int sx, int sy)
        {
            TileMask mask = new TileMask();

            Color[] colors = new Color[texture.Width * texture.Height];
            texture.GetData <Color>(colors);

            for (int y = sy; y < sy + mask.height; y++)
            {
                for (int x = sx; x < sx + mask.width; x++)
                {
                    if (colors[x + y * texture.Width] == Color.Black)
                    {
                        mask.mask[(x - sx) + (y - sy) * mask.width] = 1;
                    }
                }
            }

            return(mask);
        }
Example #3
0
 public Tile(TextureSource source, TileMask mask)
 {
     this.source = source;
     this.mask   = mask;
 }