public void Draw(SpriteBatch spriteBatch, Camera camera) { Rectangle destinationRect = new Rectangle(0, 0, Engine.TileWidth, Engine.TileHeight); Tile tempTile; foreach (MapLayer layer in this.mapLayers) { for (int y = 0; y < layer.Height; y++) { // Offset destination rectangle. destinationRect.Y = (y * Engine.TileHeight) - (int)camera.Position.Y; for (int x = 0; x < layer.Width; x++) { tempTile = layer.GetTile(x, y); if (tempTile.TileIndex >= 0 && tempTile.Tileset >= 0) { // Offset destination rectangle. destinationRect.X = (x * Engine.TileWidth) - (int)camera.Position.X; spriteBatch.Draw( this.tilesets[tempTile.Tileset].Texture, destinationRect, this.tilesets[tempTile.Tileset].SourceRectangle[tempTile.TileIndex], Color.White); } } } } }
public Player(Game game) { this.gameRef = (Game1)game; this.camera = new Camera(this.gameRef.ScreenRectangle); }