Having Problems with the ImageCollision Command
BlitzPlus Forums/BlitzPlus Programming/Having Problems with the ImageCollision Command
| ||
I'm trying to make a game like pac-man. I'm trying to make it so that when my character collides with an apple on screen, the apple disappears (as does when pac-man eats one). But, everytime my character collides with the apple, I get a message that says "Object does not exist." Thus, what do I need to do to make this error go away? My code looks like this: Graphics 640, 480, 16, 2 SetBuffer BackBuffer() Eatum = LoadImage ("Eatum.png") apple = LoadImage("Apple.png") Type Eatum Field x Field y End Type Type apple Field x Field y End Type For z = 1 To 5 a.apple = New apple a\x = -100 + 50 * z a\y = 150 Next While Not KeyDown (1) Cls DrawImage (Eatum, x,y) DrawImage (apple, a\x,a\y) If ImagesCollide (Eatum,x,y,0,apple, a\x,a\y,0) Then Delete a EndIf If KeyDown(203) Then x = x - 3 If KeyDown(205) Then x = x + 3 If KeyDown(200) Then y = y - 3 If KeyDown(208) Then y = y + 3 Flip Wend |
| ||
You need to wrap your draw apple code and your image collide code in a For a.apple=Each apple ;draw apples ;check for collisions Next What this does is it tells the program to scroll through all the a's and do this for each one. If you don't do this, the program has no idea what a is, thus resulting in an object does not exist. |
| ||
Thanks Sauer. It worked. |
| ||
Cool. It does make sense. |