Image Collision
Blitz3D Forums/Blitz3D Beginners Area/Image Collision
| ||
I'm working on a Fighters 1945 remake this week. I've racked my brain on why this code doesn't work. (The whole code is probably about 10 pages so I'm not showing it unless absolutely nessessary.) This is only a collision test between missiles (gun\ ___ ) and the enemy ships (evil\ ___ ).If evil <> Null And gun <> Null For evil.enemy1 = Each enemy1 If ImagesCollide(gun\file,gun\x,gun\y,0,evil\file,evil\x,evil\y,evil\frame) End End If Next End If The problem is there is not collision detection. (Obviously because it should end the program.) Thanks in advance |
| ||
Wow... you have weekly plans ? I struggle to have bi - yearlies... |
| ||
Not really... I could take me a LOT longer than a week to finish. I'm just starting (and taking a break from my 3D RPG) |
| ||
is gun\file actually the image handle or the path to the file? because the later is useless. |
| ||
gun\file=LoadImage("art/bullet_red.bmp") |
| ||
Maybe it is this: first you check if evil <> null, then you call For evil:If evil <> Null And gun <> Null For evil.enemy1 = Each enemy1 |
| ||
Ummm... I tried getting rid of the For... Next loop and it still doesn't work. All of the images are valid. I'm playing around with the code... still no collisions. |
| ||
That is strange, try this:For evil.enemy1 = Each enemy1 If ImagesCollide(gun\file,gun\x,gun\y,0,evil\file,evil\x,evil\y,evil\frame) then End Next And if that doesn't work, try ImagesOverlap instead (only for testing). And if that doesn't work try RectsOverlap. Check if the gun is drawn at gun\x, gun\y and the enemy at evil\x, evil\y or use a small program, such as this to test the images: Graphics 800, 600, 0, 2 SetBuffer BackBuffer() im1 = LoadImage("c:\_xfiles\grass.bmp") im2 = LoadImage("c:\_xfiles\grass.bmp") ResizeImage im1, 25, 25 ResizeImage im2, 25, 25 x2 = 400 y2 = 300 Repeat Cls x = MouseX() y = MouseY() test = ImagesCollide(im1, x, y, 0, im2, x2, y2, 0) DrawImage im1, x, y DrawImage im2, x2, y2 Text 0, 0, test Flip Until KeyHit(1) |
| ||
Sorry it took me so long to get back. Yup, that fixed it. Works great now. I would give you guys a beta, but I can't legally distribute the art. Thanks so much! |