I've faced with a problem when i tried to draw 2d game with SpriteBatch and GraphicsDevice.DrawUserPrimitives. I suppose that what is drawing with SpriteBatch has higher priority, because i can not see a result of its rendering. GraphiscDevice.DrawUserPrimitives renders only if i comment a line of rendering background. Here is my method Draw. Could you check the order of rendering. What is the reason?
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.BlanchedAlmond);
basicEffect.CurrentTechnique.Passes[0].Apply();
spriteBatch.Begin();
spriteBatch.Draw(background, new Rectangle { X = 0, Y = 0, Height = Bounds.Height, Width = Bounds.Width }, Color.White);
DrawCell();
spriteBatch.DrawString(defaultFont, "fps: " + FPS, new Vector2(10, 75), Color.DarkBlue);
spriteBatch.End();
base.Draw(gameTime);
}
private void DrawCell()
{
basicEffect.Texture = cellBody;
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, cell.Triangles, 0, cell.Triangles.Length / 3);
}
protected override void Initialize()
{
basicEffect = new BasicEffect(graphics.GraphicsDevice);
basicEffect.TextureEnabled = true;
basicEffect.Texture = bg_menu;
basicEffect.World = Matrix.Identity;
basicEffect.Projection = Matrix.CreateOrthographicOffCenter
(0, graphics.GraphicsDevice.Viewport.Width,
graphics.GraphicsDevice.Viewport.Height, 0,
0, 1);
...
}
