Ejemplo n.º 1
0
    public TileMap(TileBank _bank, PalettizedImage _sourceImage)
    {
        //
        m_tileBank = _bank;

        //
        int w = _sourceImage.m_width;
        int h = _sourceImage.m_height;

        m_width  = 64;       //(_sourceImage.m_width+7) >> 3;
        m_height = 32;       //(_sourceImage.m_height+7) >> 3;
        int sourceWidth  = w >> 3;
        int sourceHeight = h >> 3;

        //
        m_tiles    = new TileInstance[m_width, m_height];
        m_rawTiles = null;

        //
        int x, y;

        for (y = 0; y < sourceHeight; y++)
        {
            string str = y.ToString() + "=(";
            for (x = 0; x < sourceWidth; x++)
            {
                int pixel_x = x * Tile.Width;
                int pixel_y = y * Tile.Height;

                Tile         srcTile      = new Tile(_sourceImage, pixel_x, pixel_y);
                TileInstance tileInstance = m_tileBank.GetTileInstance(srcTile);
                if (tileInstance == null)
                {
                    Debug.LogException(new UnityException("PANIC! Couldn't find tile instance for tile at coordinates " + pixel_x + "," + pixel_y));
                    return;
                }

                //
                m_tiles[x, y] = tileInstance;
                str          += tileInstance.m_tileBankIndex;
                if (tileInstance.m_flipX)
                {
                    str += "x";
                }
                if (tileInstance.m_flipY)
                {
                    str += "y";
                }
                if (x < sourceWidth - 1)
                {
                    str += ",";
                }
            }

            str += ")";
            //Debug.Log( str );
        }
    }
Ejemplo n.º 2
0
    public TileMap( TileBank _bank, PalettizedImage _sourceImage )
    {
        //
        m_tileBank = _bank;

        //
        int w = _sourceImage.m_width;
        int h = _sourceImage.m_height;
        m_width = 64;//(_sourceImage.m_width+7) >> 3;
        m_height = 32;//(_sourceImage.m_height+7) >> 3;
        int sourceWidth = w >> 3;
        int sourceHeight = h >> 3;

        //
        m_tiles = new TileInstance[ m_width, m_height ];
        m_rawTiles = null;

        //
        int x, y;
        for( y=0; y<sourceHeight; y++ )
        {
            string str = y.ToString() + "=(";
            for( x=0; x<sourceWidth; x++ )
            {
                int pixel_x = x*Tile.Width;
                int pixel_y = y*Tile.Height;

                Tile srcTile = new Tile( _sourceImage, pixel_x, pixel_y );
                TileInstance tileInstance = m_tileBank.GetTileInstance( srcTile );
                if( tileInstance == null )
                {
                    Debug.LogException( new UnityException( "PANIC! Couldn't find tile instance for tile at coordinates "+pixel_x+","+pixel_y ));
                    return;
                }

                //
                m_tiles[ x, y ] = tileInstance;
                str += tileInstance.m_tileBankIndex;
                if( tileInstance.m_flipX ) str += "x";
                if( tileInstance.m_flipY ) str += "y";
                if( x<sourceWidth-1 )
                    str += ",";
            }

            str += ")";
            //Debug.Log( str );
        }
    }