So i’m making a 2D sidescroller with pixelart and i tried to zoom it all in so you can see everything properly, so i looked up how to do it with a renderTarget and added it to my existing rendering code. The thing is that on every computer i’ve tried it on, using this renderTarget works fine for a few seconds and then the framerate just gets destroyed and it takes several minutes before it even closes the game. I guess i did something wrong but i just can’t figure it out so i hope someone here can help me
this is the rendering method:
//renders everything on screen
public void render(SpriteBatch batch) {
/*
RenderTarget2D target = new RenderTarget2D(batch.GraphicsDevice, (int)Math.Ceiling(camera.cameraSize.X), (int)camera.cameraSize.Y);
batch.GraphicsDevice.SetRenderTarget(target);
*/
batch.Begin();
if (manager != null) {
if (manager.currentScene != null) {
if (manager.currentScene.tiles != null) {
if(manager.player.currentSprite != null) {
//renders shadows behind the player
foreach (playerShadow pos in lastPlayerPositions) {
if (pos.time >= amountOfShadows) {
toRemove = pos;
} else {
if (pos.sprite != null) {
batch.Draw(pos.sprite, pos.pos - camera.cameraPos, Color.White * (1 / (pos.time * 2)));
}
pos.time += 1;
}
}
if (toRemove != null) {
lastPlayerPositions.Remove(toRemove);
}
//renders the player
batch.Draw(manager.player.currentSprite, manager.player.pos - camera.cameraPos);
lastPlayerPositions.Add(new playerShadow(manager.player.pos, 0, manager.player.currentSprite));
}
//renders the tiles on screen
for (int x = 0; x < manager.currentScene.sceneSize.X; x++) {
for (int y = 0; y < manager.currentScene.sceneSize.Y; y++) {
Tile toRender = manager.currentScene.tiles[x, y];
if (toRender != null) {
if(toRender.sprite != null) {
batch.Draw(toRender.sprite, new Vector2(toRender.pos.X * (int)sizes.tileSize, toRender.pos.Y * (int)sizes.tileSize) - camera.cameraPos);
}
}
}
}
}
}
}
batch.End();
/*
batch.GraphicsDevice.SetRenderTarget(null);
batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);
batch.Draw(target, new Rectangle(0, 0, batch.GraphicsDevice.DisplayMode.Width, batch.GraphicsDevice.DisplayMode.Height), Color.White);
batch.End();
*/
}
The commented parts are what make the renderTarget work and everything is fine when i delete it besides everything being really small of course. So i guess it’s gotta be something about the renderTarget that i’m doing wrong but i just can’t figure it out