Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I would like to make a 2D tile based game, but, to make it look a bit prettier, I would need to skew textures so that it would look more like a 2.5D game. So I thought maybe I should skew textures to something like this:

enter image description here

So far I only found one topic about it - http://forums.create.msdn.com/forums/p/37143/215098.aspx#215098

But I don't really understand it. Maybe some of you do, can tell me how to skew my sprites?

share|improve this question
3  
The link describes two ways to solve this. The "proper" way is to treat this completely in 3D as textured quads, instead of using the SpriteBatch. This way you can just offset the top vertices yourself when creating the quads. The other solution uses a custom pixel shader for SpriteBatch which is provided in the link, sets the texture adress mode to clamp, and it requires that you add a one pixel transparent border around your textures. Personally I would recommend the first solution. –  David Gouveia Jul 15 '12 at 17:07
    

1 Answer 1

If you use a textured quad, you have some additional flexibility over the geometry that you wouldn't have with a SpriteBatch. This will allow you to implement the skewing you're after. You can then implement the skew:

  • Pinch the top two vertices in on the X axis (or push the bottom two vertices out along the same axis). That is, create a quad with corner points at, say, (-0.5, 1.0f), (0.5, 1.0), (1.0, -1.0), (-1.0, -1.0). This is the approach you'd have to take if you are using an orthographic projection elsewhere.

  • Push the top two vertices away from the camera along the Z axis (give them Z coordinates of, say, 0.5 if the rest of your quad is in the Z = 0.0 plane). If you use a perspective projection, this will achieve the skew naturally.

Both options will potentially have slightly different results in terms of the appearance of the texture mapped to the quad, and both approaches are more appropriate for certain kinds of existing rendering pipelines (primarily based around the projection matrix you are currently using). You'll have to pick the one that best fits your code and your desired visual style.

Note that abandoning SpriteBatch means you lose some of the batching optimizations it makes for you, which you may need to re-implement depending on the overall performance (and performance bar) of your game.

(Also note that a third option would be to just author the sprite textures with the desired perspective distortion built-in, which means you can simply continue to use SpriteBatch, but adjusting the perspective would be difficult as it would require re-authoring your sprites.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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