0

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 :)

4

1 回答 1

0

您正在绘制到 RenderTarget 而不是 BackBuffer。当您不向 BackBuffer 绘制任何内容时,它默认为紫色。在 RenderTarget 设置为 null 时进行绘制以绘制到 BackBuffer,这决定了您在屏幕上看到的内容。RenderTargets 用于在屏幕外绘制东西。

于 2013-07-23T17:23:27.073 回答