2
\$\begingroup\$

Usually XNA increases X coordinate to right and Y to down. Like this:

Exapmple

But in my project i have 2D map. Drawing tile with bigger Y coodinate below OX looking strange (usually people imagines these tiles above OX).

Yeah i can just use

spriteBatch.Draw(Turf.Texture, new Rectangle(Turf.X*32, Turf.Y*32*-1),Color.White);

//32 is width and height of tile, also code simplified

But it makes a code harder and uglier. Don't XNA have any setting \ variable to make spritebatch counting Y to top?

\$\endgroup\$
1
\$\begingroup\$

alternatively you can create your own functions to do it, like:

void drawSprite(Texture2D texture, Rectangle rect, Color color)
{
    spriteBatch.Draw(texture, new Rectangle(/*modifying the given rectangle*/), color);
}
\$\endgroup\$
  • \$\begingroup\$ this is bad idea because my draw code already difficult and can't be modificied so easy \$\endgroup\$ – cat Nov 29 '15 at 13:10
  • 3
    \$\begingroup\$ Why would this be a bad idea? It creates the alternate coordinate system separate from your existing code. You could even create the function as an extension of SpriteBatch. This way the complexity is not added to yor existing functions. In fact this is I think the only way of doing what you ask. You seem to want your own coordinate system, because reversing the Y axis (which you can accomplish by initializing the spritebatch using a Matrix) would also flip your sprites upside down. \$\endgroup\$ – Felsir Nov 30 '15 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.