I'm trying to get textures to draw with DebugView. Yet, I can't see the textures :(
These are the steps I followed:
I create a BasicEffect in Game ::LoadContent():
effect = new BasicEffect(GraphicsDevice);
Then in my Game::Draw: (scale is something I can tweak. default value is set to 50f)
Matrix proj = Matrix.CreateOrthographic(scale * graphics.GraphicsDevice.Viewport.AspectRatio, scale, 0, 1);
Matrix view = Matrix.Identity;
effect.World = Matrix.Identity;
effect.View = view;
effect.Projection = proj;
effect.TextureEnabled = true;
effect.VertexColorEnabled = true;
mDebugView.RenderDebugData(ref proj, ref view);
SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, effect);
In my Paddle:: Draw =>
new Vector2(16, 16),
where Texture is 32 x 32, Generate Mipmap is set to true, Resize to power of 2 : true,
mBody = Farseer's Body,
scaleFactor used : 0.001f
Can someone please tell me where am I going wrong with the math ?
After a lot of hair loss, I've finally figured out what the problem was. The math was all correct.
Here's what I was missing:
SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, DepthStencilState.Default, RasterizerState.CullNone, effect);
One more thing to note:
scale of 0.1f worked good for me. Actually, a factor of 0.1875f was pixel perfect, since the width of the box was 6 meters, and width of the texture was 32 pixels. Now 32 pixels in meters happen to be 6/32 = 0.1875f
I'm writing a series of tutorials, and will be posting this part soon. I've posted two tutorials on basics and creating a simple pong game. I'll be adding more and publishing those soon, where you can read the details.
Jan 31, 2011 at 11:59 AM
Just let us know when they are ready than we can put up a link to your tutorials in our documentation section somewhere.