Pregunta

I'm currently making a 2D side-scroller game with XNA for my personal project. My goal for the moment is to have fun with shaders. But I'm actually stuck by the SetRenderTarget(RenderTarget2D) method, I don't understand why once i call it the game gets a full purple screen.

I searched everywhere and I still don't understand where the problem is, but i think its maybe due to my way of beginning the spritebatch.

public void Draw(GraphicsDevice graphics, SpriteBatch spriteBatch, RenderTarget2D mainScene)
    {
        graphics.SetRenderTarget(mainScene);
        graphics.Clear(Color.Black);
        spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, _camera.GetViewMatrix(Parallax));

        foreach(Sprite sprite in Sprites)
            sprite.Draw(spriteBatch);

        spriteBatch.End();
        graphics.SetRenderTarget(null);            
    }

Any ideas ? Thanks in advance :)

¿Fue útil?

Solución

You are drawing to a RenderTarget not the BackBuffer. When you draw nothing to the BackBuffer it defaults to a purple color. Draw while the RenderTarget is set to null to draw to the BackBuffer which dictates what you see on the screen. RenderTargets are for drawing things off screen.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top