# Draw depth works on WP7 emulator but not device

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!

• 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? – Luke Sep 25 '12 at 10:52
• I only know of extension methods, so you could add float.ARMEpsilon() (or Single.ARMEpsilon()) :/ – user13213 Sep 25 '12 at 11:09
• 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. – Luke Sep 25 '12 at 11:20