Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building your First Mobile Game using XNA 4.0

You're reading from   Building your First Mobile Game using XNA 4.0 A fast-paced, hands-on guide to building a 3D game for the Windows Phone 7 platform using XNA 4.0

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849687744
Length 158 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Thomas Goussaert Thomas Goussaert
Author Profile Icon Thomas Goussaert
Thomas Goussaert
Brecht Kets Brecht Kets
Author Profile Icon Brecht Kets
Brecht Kets
Arrow right icon
View More author details
Toc

Mixing 2D and 3D


One thing we need to know when mixing 2D and 3D is that the order of drawing is important. If we draw our 2D graphics last, they will be in front of our models. This can be necessary for the HUD (heads up display) for instance. A background however needs to be behind the model, so we need to draw it first.

Also, calling the End method on a SpriteBatch object doesn't reset the states. We need to do this manually, and if we don't, our model won't appear correctly. We need to set the blend state, the depth stencil state, and the sampler states before drawing the model. The blend state controls how colors are blended, or mixed, together. The depth stencil state controls how depth impacts rendering (if we don't set this, our model will have no depth). And finally, the sampler state defines how textures are sampled, including the method of filtering and level of detail.

graphics.GraphicsDevice.BlendState = BlendState.Opaque;
graphics.GraphicsDevice.DepthStencilState =DepthStencilState...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image