Rendering in Landscape Mode
At the time of writing, the XNA 3.0 CTP does not have any internal mechanism for rendering games in landscape mode. This leaves it up to the developer to implement a system on their own. So far there seems to be three methods for doing this:
1) Render all your sprites by manually adjusting their position and rotation in your calls to SpriteBatch.Draw. This is the initially simple way, but quickly becomes a pain to keep track of. I haven't seen anyone go this route, but it is there.
2) Render all your sprites by using the SpriteBatch.Begin overload that takes a transform matrix. This works great for rotating lots of sprites at once, but the Zune currently has poor image filtering, so this can leave your sprites looking a little ugly.
3) Render your game to a render target and then rotate that when drawing it to the screen to create the landscape mode effect. This is my preferred solution and also happens to solve the filtering issue of the second solution. In my mind this is the best route for any landscape Zune game to go.
So let's take a look at some code for that third solution. It's really simple if you've used render targets. If not, it's still not the hardest thing to do. First we'll create a render target in our Game1 class:
Next we create the render target in the LoadContent method. Since our goal is to render in landscape mode at 320x240 (instead of the default 240x320 portrait mode), we use that resolution when creating the render target:
renderTarget = new RenderTarget2D( GraphicsDevice, 320, 240, 0, SurfaceFormat.Color);
Then when we render our game in the Draw method, we set the render target, draw the game, and then draw the render target to the screen. The nice part is our sprites can just be drawn as if you have a 320x240 screen so you don't have to adjust any of the positions or rotations at all:
//set the render target GraphicsDevice.SetRenderTarget(0, renderTarget); //clear the screen graphics.GraphicsDevice.Clear(Color.Black); //TODO: Draw entire game here //call base.Draw here to ensure any //graphical components are rendered base.Draw(gameTime); //resolve the target GraphicsDevice.SetRenderTarget(0, null); //draw the texture rotated spriteBatch.Begin(); spriteBatch.Draw( renderTarget.GetTexture(), new Vector2(120, 160), null, Color.White, MathHelper.PiOver2, new Vector2(160, 120), 1f, SpriteEffects.None, 0); spriteBatch.End();