private void Render()
{
if(state == GameState.Menu)
{
_Background = (new Surface(resourcepath + "//titlescreen.bmp")).Convert();
Button playbutton = new Button(288, 360, 64, 32, GameEngine.resourcepath + "//PlayButton.bmp");
playbutton.OnClick += new ButtonEventHandler(MouseEvents);
_Background.Blit(playbutton.surf, new Rectangle(playbutton.X, playbutton.Y, playbutton.Width, playbutton.Height));
_Screen.Blit(_Background, new Rectangle(new Point(0,0), _Background.Size));
_Screen.Flip();
}
if(state == GameState.Pregame)
{}
if(state == GameState.Ingame)
{
_Background = new Surface(resourcepath + "//background.bmp");
//_BackBuff = _Screen.CreateCompatibleSurface(640, 480, true);
_Background.Blit(_Background, new Point(0,0));
_Background.Blit(player.Surf, player.Location);
_Screen.Blit(_Background, new Point(0,0));
_Screen.Flip();
}
}
SDL CreateCompatible Surfaces performance hit
I am currently working on my first 'game'. I am dabbling through SDL, and I'm using the SDlDotNet library, but all you C++ die-hards should be able to read it(I learned it by look at C++ examples). I have a performance hit in this function, I'm absolutely sure it's this function, because I commented it out and there was no problem.
Please see if you can help me find it.
Oh, and I think it's in both the Ingame and Menu parts.
Now I am no C# expert, but that is a lot of new's I see in there. I think the problem is that you are allocating memory every frame. This would cause the performance problems you are describing. What you should try is making the variables before hand and loading all the settings so you are not always creaing new ones. Just one suggestion [wink]
Yea, I thought of that too, but the program works good for about 15 seconds then, it starts having performance spikes like a heartbeat almost. Maybe it's alive ^_^! I was going to change it, but I couldn't think of a good way, but I just now thought of making an event fire when the game state changes, and I could change the _Background surface in that.
You're adding new memory each frame, which mean's C# garbage collection is eventually going to start swapping new memory for old memory each loop. You may even be hitting a hardware memory max, which mean's new memory will be allocated on your harddrive as virtual memory.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement