示例#1
0
        public string DrawLevel(SpriteBatch sb, Camera2D camera, ScreenInfo screenInfo)
        {
            if (sb == null)
                return "Level.DrawLevel - Error: Null SpriteBatch\n";

            Vector2 topLeft = camera.ToVirtual(Vector2.Zero, false);
            Vector2 bottomRight = camera.ToVirtual(screenInfo.screenDimensions, false);

            uint numColumns, numRows;
            int curTileWidth = 0, curTileHeight = 0;
            for (int i = 0; i < numBackgroundLayers; ++i)
            {
                numColumns = backgroundRowTiles[i];
                numRows = backgroundRowColumns[i];
                if(numColumns > 0 && numRows > 0)
                {
                    curTileWidth = backgrounds[i][0][0].getTileWidth();
                    curTileHeight = backgrounds[i][0][0].getTileHeight();
                }
                // TODO don't run through the tiles not near the screen
                for (uint x = 0; x < numColumns; ++x)
                {
                    for (uint y = 0; y < numRows; ++y)
                    {
                        if ((((x + 1) * curTileWidth) < topLeft.X || (x * curTileWidth) > bottomRight.X) &&
                            (((y + 1) * curTileHeight) < topLeft.Y || (y * curTileHeight) > bottomRight.Y))
                            continue;

                        sb.Draw(backgrounds[i][x][y].getTexture(), new Vector2(x * curTileWidth, y * curTileHeight));
                    }
                }
            }

            //testObj.SetPosition(new Vector2(bottomRight.X - 100, bottomRight.Y - 100));
            //testObj.SetPosition(new Vector2(topLeft.X, topLeft.Y));
            //testObj.Draw(sb, camera, curScreenPos, curScreenDimensions, pxWidth, pxHeight);
            return null;
        }