I am making a game on a WP7 device using C# and XNA. I have a system where I always want the object the user is touching to be brought to the top, so every time it is touched I add float.Epsilon to its draw depth (I have it set so that 0 is the back and 1 is the front).

On the Emulator that all works fine, but when I run it on my device the draw depths seem to be completely random.

I am hoping that anybody knows a way to fix this. I have tried doing a Clean & Rebuild and uninstalling from the device but that is no luck. My call to spritebatch.Begin is:

spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);

and to draw I use

spriteBatch.Draw(Texture, new Rectangle((int)X, (int)Y, (int)Width, (int)Height), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, mDrawDepth);

Where mDrawDepth is a float value of the draw depth (likely to be a very small number; a small multiple of float.Epsilon.

Any help much appreciated, thanks!


This note from MSDN seems relevant:

On ARM systems, the value of the Epsilon constant is too small to be detected, so it equates to zero. You can define an alternative epsilon value that equals 1.175494351E-38 instead.

  • \$\begingroup\$ Thank you! I know in C# you can do Class Extensions but do you know if there is a way that I could add it so that I can do something like float.ARMEpsilon? \$\endgroup\$
    – Luke
    Sep 25 '12 at 10:52
  • \$\begingroup\$ I only know of extension methods, so you could add float.ARMEpsilon() (or Single.ARMEpsilon()) :/ \$\endgroup\$
    – user13213
    Sep 25 '12 at 11:09
  • \$\begingroup\$ After searching around and trying it out it seems you can't do static extension methods as extension methods (on an object) are already static. I've just done a private const float at the top of the file that uses it. \$\endgroup\$
    – Luke
    Sep 25 '12 at 11:20

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.