Game slowdown

BlitzPlus Forums/BlitzPlus Programming/Game slowdown

supermeerkat(Posted 2005) [#1]
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?


Nicstt(Posted 2005) [#2]
are you deleting the type info you dont need?


supermeerkat(Posted 2005) [#3]
Yup - when the monster dies, his type is deleted after his associated image has been freed.


Grey Alien(Posted 2005) [#4]
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.


supermeerkat(Posted 2005) [#5]
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.


skyfire1(Posted 2005) [#6]
you probably left debug mode on. debug mode tends to slow down programs.