Killing those sprites
Blitz3D Forums/Blitz3D Beginners Area/Killing those sprites
| ||
I am playing with a few ideas, mainly to test collisions on bitmaps. I have a program that has four sprites running across the screen in various directions. What I did is to change the mouse pointer to a VERY simply crosshair and then looking for collisions. When I shoot the first bitmap, it disapears off the screen (in a very dirty way). But then it never detects any after that. Where am I going wrong? Code: Graphics3D 1024,768,32 SetBuffer BackBuffer() Global font Global backgr Global lemm1,lemm2,lemm3,lemm4 Global lemm1h,lemm2h,lemm3h,lemm4h Global lemmimage Global l1x,l1y, l2x, l2y, l3x, l3y, l4x, l4y Global cross font=LoadFont("Arial",12,False,False,False) SetFont font ;backgr=LoadImage("") lemmimage=LoadImage("lemm.png") cross=LoadImage("cross.png") lemm1=lemmimage lemm2=lemmimage lemm3=lemmimage lemm4=lemmimage mainloop() Function mainloop() While Not KeyHit(1) ;DrawImage backgr,0,0 Cls DrawImage lemm1,l1x,l1y DrawImage lemm2,l2x,l2y DrawImage lemm3,l3x,l3y DrawImage lemm4,l4x,l4y DrawImage cross,MouseX(),MouseY() ;movement (levels) l1x=l1x+1:l1y=l1y+2 l2x=l2x+4:l2=l2y+1 l3x=l3x+2:l3y=l3y+3 l4x=l4x+1l4y=l4y+0 ;collision detection If ImagesCollide (cross,MouseX(),MouseY(),0,lemm1,l1x,l1y,0) And MouseHit(1) Then l1x=10000 If ImagesCollide (cross,MouseX(),MouseY(),0,lemm2,l2x,l2y,0) And MouseHit(1) Then l2x=10000 If ImagesCollide (cross,MouseX(),MouseY(),0,lemm3,l3x,l3y,0) And MouseHit(1) Then l3x=10000 If ImagesCollide (cross,MouseX(),MouseY(),0,lemm4,l4x,l4y,0) And MouseHit(1) Then l4x=10000 Flip Wend End Function |
| ||
Hey, first thing i notice is your setting up graphics for a 3d scene. It has nothing to do with your problem though :) just thought i'd mention it. The problem your having is the MouseHit() command. For some reason or other, it take a length of time to reset. Don't know if it's everytime that flip is called. But, if you change the MouseHit() to MouseDown() command, everything works fine :) |
| ||
Also, try and make use of the DebugLog() command too. It's very useful for finding out which line is running correctly and which ones aren't. For instance, i put DebugLog("working!") at the end of each IF STATEMENT, to see what lines weren't being executed, which quickly led me on to the first IF only being executed. Just remember that problem with MouseHit(). |
| ||
Excellant.. thanks for that. I wil look at the debuglog as well.. sounds like a good plan. Yeah I know I setup 3d screen,it was purley because once I get my programming knowledge up to scratch I was going to turn this into a 3d game.. but err..I should reallystop being so sloppy.. Does running 2d graphics in a 3d screen slow things down or make no difference? Thanks again Mango |
| ||
Alternatively, doing this might sort it (ie. poll MouseHit just the once)...If MouseHit (1) If ImagesCollide (cross,MouseX(),MouseY(),0,lemm1,l1x,l1y,0) Then l1x=10000 If ImagesCollide (cross,MouseX(),MouseY(),0,lemm2,l2x,l2y,0) Then l2x=10000 If ImagesCollide (cross,MouseX(),MouseY(),0,lemm3,l3x,l3y,0) Then l3x=10000 If ImagesCollide (cross,MouseX(),MouseY(),0,lemm4,l4x,l4y,0) Then l4x=10000 EndIf |
| ||
Does running 2d graphics in a 3d screen slow things down or make no difference? Mixing 2D and 3D graphics can be fairly slow on some peoples systems due to some defective video card drivers that have been released in the past. |