[SOLVED] RenderTarget is black after drawing.

Hey guys,
so im working on my own game and i want to draw the map on starting the game.
I am drawing the map to a rendertarget but when I draw it to the game itself it is just a black square.
My code how im doing it:

graphicsDevice.SetRenderTarget(_MapRenderTarget) graphicsDevice.Clear(Color.Black) Using spritebatch As New SpriteBatch(graphicsDevice) spritebatch.Begin() Dim x As Integer = 0 Dim y As Integer = 0 For Each tileInfo In mapInfo.MainLayer.TileIndex Dim xPos As Integer Dim yPos As Integer yPos = CInt(Fix(tileInfo / 8)) xPos = tileInfo - yPos * 8 spritebatch.Draw(mapInfo.TileSet, New Rectangle(x * 32, y * 32, 32, 32), New Rectangle(xPos * 32, yPos * 32, 32, 32), Color.Black) x += 1 If (x * 32) > mapInfo.Size.X Then y += 1 x = 0 End If Next spritebatch.End() End Using graphicsDevice.SetRenderTarget(Nothing) Return DirectCast(_MapRenderTarget, Texture2D)

When im trying to draw it directly onto the scene without the rendertarget it is working great.
Someone has an idea what the problem is?

PS: sorry for my bad english.

Protip: your code looks a lot nicer and gets some syntax highlighting if you wrap it in triple backticks e.g.

public String Hello() {
    Console.WriteLine("Hello World!");
}

Does it work if you render directly to the backbuffer? How are you drawing the returned texture to the backbuffer?

Thank you for the tip.
I just found out what the problem was…
when i use spritebatch.draw (in the code above) i am using the black for the color.
I just changed it to white and it worked.

1 Like

What char is backtick ? “`” ? Does it need 3 at start and at the end ? 3 before each row ?

Yes ` is a backtick. You need 3 at the start and 3 at the end of the block. For inline code you can wrap it in single backticks. It will show up like this.