Rectangle() 공개 메소드

public Rectangle ( int position ) : Rectangle
position int
리턴 Microsoft.Xna.Framework.Rectangle
예제 #1
0
        public void Draw(SpriteBatch spriteBatch, TileSet tileset, Vector2 position)
        {
            float randyRow = (float)position.Y / tileset.TileHeight;
            float randyCol = (float)position.X / tileset.TileWidth;
            float viewportRows = spriteBatch.GraphicsDevice.Viewport.Height / tileset.TileHeight;
            float viewportCols = spriteBatch.GraphicsDevice.Viewport.Width / tileset.TileWidth;
            float screenRows = Rows;
            float screenCols = Columns;

            float top = Math.Max(0, randyRow - viewportRows / 2);
            if (randyRow > screenRows - viewportRows / 2)
                top = screenRows - viewportRows;
            float left = Math.Max(0, randyCol - viewportCols / 2);
            if (randyCol > screenCols - viewportCols / 2)
                left = screenCols - viewportCols;

            int x = 0;
            int y = 0;

            int layer = 0;

            foreach (Terrain terrain in terrainList)
            {
                float depth = layer * 0.02f;

                if (layer < Map.ABOVE_PLAYER_LAYER_START)
                {
                    depth += 0.1f;
                }
                else
                {
                    depth += 0.5f;
                }
                layer++;
                y = 0;
                foreach (TileRow tileRow in terrain.TileRowList)
                {
                    x = 0;
                    /*
                    if (y < top - 1)
                    {
                        y++;
                        continue;
                    }

                    if (y > bottom)
                    {
                        break;
                    }
                    */
                    foreach (Tile tile in tileRow.TileList)
                    {
                        /*
                        if (x < left - 1)
                        {
                            x++;
                            continue;
                        }

                        if (x > right)
                        {
                            break;
                        }*/
                        if (randyRow < viewportRows / 2)
                        {

                        }
                        spriteBatch.Draw(
                            tileset.Texture,
                            new Rectangle(
                                (int)((x * tileset.TileWidth) + (tileset.TileWidth / 2) - (left * tileset.TileWidth)),
                                (int)((y * tileset.TileHeight) + (tileset.TileHeight / 2) - (top * tileset.TileHeight)),
                                tileset.TileWidth, tileset.TileHeight),
                                tileset.Rectangle(tile.Position),
                                Color.White,
                                MathHelper.ToRadians(tile.Rotation),
                                new Vector2(tileset.TileWidth / 2, tileset.TileHeight / 2),
                                SpriteEffects.None, depth);
                        x++;
                    }
                    y++;
                }
            }
        }