I noticed that the framerate of BlitzMax can drop dramatically with CollideImage. Take e.g. the following code I found on this forum.
With nine images everything runs fine, but increasing the number of images to 50 the app becomes very slow. Is something wrong with this code?
Thanks.
Graphics 640,480,32 Global tList:TList = New TList Type img Field image:timage Field x:Float,y:Float Field sx:Float,sy:Float Field r:Float,sr:Float Function Create:img(f:String) i:img = New img i.image = LoadImage(f) i.x = Rnd(20,620) i.y = Rnd(20,460) i.sx = Rnd(-3,3) i.sy = Rnd(-3,3) i.r = Rnd(0,360) i.sr = Rnd(-5,5) tList.Addlast i Return i End Function Method Update() x :+ sx y :+ sy r :+ sr If x>620 And sx>0 sx = -sx ElseIf x<20 And sx<0 sx = -sx EndIf If y>460 And sy>0 sy = -sy ElseIf y<20 And sy<0 sy = -sy EndIf SetBlend ALPHABLEND SetScale 0.3,0.3 SetRotation r SetColor 255,255,255 ' Draw this image in collision layer 1 CollideImage(image,x,y,0,0,1) ' Test all other images with collision layer 1 For Local i:img = EachIn tList If i<>Self ' This tests i.image for collision with layer 1 If CollideImage(i.image,i.x,i.y,0,1,0) ' We have a collision so let's make it red! SetColor 255,0,0 EndIf EndIf Next ' Clear all collision layers ResetCollisions() DrawImage image,x,y End Method End Type For j = 0 To 9 i:img = img.create("bmax120.png") Next Repeat Cls For i:img = EachIn tList i.Update() Next Flip FlushMem Until KeyHit(KEY_ESCAPE)
With nine images everything runs fine, but increasing the number of images to 50 the app becomes very slow. Is something wrong with this code?
Thanks.