Created
November 8, 2012 12:48
-
-
Save kenpower/4038604 to your computer and use it in GitHub Desktop.
Scrolling Background Terrain Drawing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int vpw = graphics.GraphicsDevice.Viewport.Width; | |
int vph = graphics.GraphicsDevice.Viewport.Height; | |
Rectangle rect = new Rectangle(0, 0, vpw, vph); | |
spriteBatch.Begin(); | |
//construct a rectangle to select an area of background to draw | |
//position(upper left of) rectangle is camera position minus halh size of viewport | |
Rectangle terrainRect=new Rectangle( | |
(int)(camera.Position.X-vpw/2), | |
(int)(camera.Position.Y-vph/2), | |
graphics.GraphicsDevice.Viewport.Width, | |
graphics.GraphicsDevice.Viewport.Height); | |
spriteBatch.Draw(terrain, Vector2.Zero, | |
terrainRect, Color.White); | |
spriteBatch.End(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment