6
\$\begingroup\$

What's the correct technique for getting smooth sprite translations with XNA?

I've been developing the WP7 version of an app for a startup, so when we heard Angry Birds got ported today we wanted to check it out and compare. Angry Birds on WP7 had the sub-pixel blur problem with the bird sprites, whereas iPhone, Android, and Chrome all had smooth movement.

\$\endgroup\$
5
\$\begingroup\$

It sounds like they are accidentally rounding their sprite positions to the nearest pixel. This can happen automatically if you use the SpriteBatch.Draw() call that takes a Rectangle as the position of the sprite, since XNA's Rectangle uses integers instead of floats to represent position.

If sprites are drawn with integer coords, then sub-pixel rendering will not occur, and sprites will appear to snap from one pixel position to the next, instead of blending smoothly between them.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ That explains why, would the assumption for a fix then be to use the overload that accepts a Point()? \$\endgroup\$
    – Nate
    Jun 30 '11 at 5:06
  • 1
    \$\begingroup\$ You mean a Vector2, and yes. And to make sure that the floating point coordinates in the Vector2 struct are not being rounded to an integer value! \$\endgroup\$
    – Olhovsky
    Jun 30 '11 at 6:11
  • \$\begingroup\$ Snapping to the nearest pixel can however make for a clearer image, for example when using SpriteFonts, however this I only tested on Windows. \$\endgroup\$ Jun 30 '11 at 8:17
  • \$\begingroup\$ It's difficult to tell exactly whether the blur is occurring because of the sub-pixel rendering or because of the perceived blur from snapping to pixels. Which one actually results in the clearer image, at least in the context of little sprites on a cell phone screen flying around with Box2D physics? \$\endgroup\$ Jun 30 '11 at 14:00
  • \$\begingroup\$ Haha, yes. Can you tell I was working in a different .NET stack, where its Point instead of Vector2? \$\endgroup\$
    – Nate
    Jun 30 '11 at 14:51
2
\$\begingroup\$

It could have to do with the framerate or it could have to do with the fact that xna does sub pixel rendering

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .