Game slowdown
BlitzPlus Forums/BlitzPlus Programming/Game slowdown
| ||
Hi Guys I have written a routine that I use to apply a random colour to my monsters - see code below. Function setMonsterColor(monsterType%) ;create graphics m\imgHandle = CreateImage (35,42,8) ;set that graphic as buffer SetBuffer ImageBuffer (m\imgHandle,0) ;Get monster frames For ctr = monsterType To (monsterType + 1) SetBuffer ImageBuffer (m\imgHandle,ctr - monsterType) setClsColor(m\imgColor) Cls DrawImage imgMonstersStandard ,0,0,ctr Next ;Get monster birth and death frames For ctr = 20 To 25 SetBuffer ImageBuffer (m\imgHandle,(ctr - 20) + 2) setClsColor(m\imgColor) Cls DrawImage imgMonstersStandard ,0,0,ctr Next SetBuffer CanvasBuffer(canvas) MaskImage m\imgHandle,0,0,255 MidHandle m\imgHandle End Function (I think it's pretty straight forwards, though I may be wrong). Now since I've implemented this routine, the game starts to get slower and slower, and memory usage slowly creeps up. The only thing I can think of is that the images being created and assigned to m\imgHandle are not being freed upon the monster death, however, I'm using the freeimage command as recommended in the help files, to get rid of the imagehandle e.g. FreeImage m\imgHandle I'm at a bit of a loss, can any one help please? |
| ||
are you deleting the type info you dont need? |
| ||
Yup - when the monster dies, his type is deleted after his associated image has been freed. |
| ||
The only logical thing is that you are calling setMonsterColor (i.e. too many times) more than you are deleting the monsters OR you added some other code elsewhere that has caused the problem OR your image freeing and type deletion code is wrong. You could stick a counter in the setMonsterColor and deletion funcitons to see if they are the same number when your program exits. That'll tell you if you have made a mistke. |
| ||
The problem is fixed now, but I don't know what I did. In my frustration, I decided to leave the above problem alone and generally tidying up the code, and when I ran it later to check something I noticed the slowdown has gone. How strange! Thanks anyway for your suggestions guys. |
| ||
you probably left debug mode on. debug mode tends to slow down programs. |