Sign in to follow this  
Ghost Clock

XNA Spritebatch question(s)

Recommended Posts

Ghost Clock    130
My second question may be more important but what that is depends on the answers to my first questions. That is, why is Spritebatch set up so that when drawing, Vector2.Zero refers to the upper left corner instead of the center of the screen and why are positive Y coordinates below this origin instead of above?

Having it set up this way isn't a big deal in itself but it doesn't seem consistant with the way XNA does anything else by default, such as mesh drawing and the 360 pad thumbstick vector2s.

Share this post


Link to post
Share on other sites
?????????    199
XNA isn't the only API which does this. Almost all 2D APIs do this.
The SpriteBatch class is designed with 2D in mind. Meaning, if you have ever worked with 2D graphics before, you would see that it is much easier to refer to things from a corner of the screen. (btw, you can apply a transform matrix in SpriteBatch.Begin(...) to offset your coordinates)
3D is based on perspective projection - meaning convergence to the center point of the viewport - so it is easier to work from the center and offset things depending on how much focus you want the player to have on them.
On the other hand, 2D is based on parallel-orthographic projection - meaning the entire viewport is viewed from the same distance - so the user should be focused on the entire scene, making it easier to work with from a corner (a relatively insignificant spot)

Share this post


Link to post
Share on other sites
Ghost Clock    130
[quote name='wiz3kid' timestamp='1341244861' post='4954943']
(btw, you can apply a transform matrix in SpriteBatch.Begin(...) to offset your coordinates)
[/quote]
Which I have done and so this will be my second question; what are my options with the translation Matrix I provide to Spritebatch? Would it be possible to flip the Y coordinates upside down? Can this be done without reversing the X? Would I have to flip all my textures to accomidate?

The issue is, my game is mainly 3D but for [s]debugging[/s]* and level editing, I use a combination of both 3D and 2D. I can manipulate my 3D data to account for the Spritebatch, it's nothing hard to figure out but if it's possible, I'd much rather manipulate the Spritebatch to account for how my 3D is already working.

*I mean designing and tweaking the game with my debug build. Nothing related to the spritebatch code is part of the Release build, which is why I feel It'd be better to make it work like the rest of the game. Edited by Ghost Clock

Share this post


Link to post
Share on other sites
6677    1054
You could define your own wrapper class around spritebatch that deals with the inversion of the y axis for you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this