public void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            Rectangle destination = new Rectangle(0, 0, TileEngine.TileWidth, TileEngine.TileHeight);
            int startX, endX, startY, endY;
            Tile tile;

            foreach (MapLayer layer in mapLayers)
            {
                startX = (int)Math.Floor(camera.Position.X / (TileEngine.TileWidth * camera.Zoom));
                endX = (int)MathHelper.Clamp(((camera.Position.X + camera.ViewportRectangle.Width) / (TileEngine.TileWidth * camera.Zoom)) + 1, 0, layer.Width);

                startY = (int)Math.Floor(camera.Position.Y / (TileEngine.TileHeight * camera.Zoom));
                endY = (int)MathHelper.Clamp(((camera.Position.Y + camera.ViewportRectangle.Height) / (TileEngine.TileHeight * camera.Zoom)) + 1, 0, layer.Height);

                for (int y = startY; y < endY; y++)
                {
                    destination.Y = y * TileEngine.TileHeight;

                    for (int x = startX; x < endX; x++)
                    {
                        tile = layer.GetTile(x, y);

                        if (tile.TileIndex == -1 || tile.Tileset == -1)
                            continue;

                        destination.X = x * TileEngine.TileWidth;

                        spriteBatch.Draw(
                            tilesets[tile.Tileset].Texture,
                            destination,
                            tilesets[tile.Tileset].SourceRectangles[tile.TileIndex],
                            Color.White);
                    }
                }
            }
        }
Esempio n. 2
0
 public Player(Game1 game)
 {
     gameRef = game;
     camera = new Camera(gameRef.ScreenRectangle);
 }
 public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Camera camera)
 {
     spriteBatch.Draw(
         texture,
         position,
         animations[currentAnimation].CurrentFrameRect,
         Color.White);
 }