| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <html>
- <head>
- <title>Blitz3D Docs</title>
- <link rel=stylesheet href=../css/commands.css type=text/css>
- </head>
- <body>
- <h1>ImagesOverlap (image1,x1,y1,image2,x2,y2)</h1>
- <h1>Parameters</h1>
- <table>
- <tr>
- <td>
- image1 = first image to test
<br />
- x1 = image1's x location
<br />
- y1 = image1's y location
<br />
- image2 = second image to test
<br />
- x2 = image2's x location
<br />
- y2 = image2's y location
- </td>
- </tr>
- </table>
- <h1>Description</h1>
- <table>
- <tr>
- <td>
- This is a very fast, simple collision type command that will allow you to determine whether or not two images have overlapped each other. This does not take into account any transparent pixels (see ImagesCollide).
<br />
-
<br />
- As with any collision detection system in Blitz, you will need to know the variable names of the two images, and their X and Y locations at the moment collision checking occurs.
<br />
-
<br />
- In many cases, you might be able to get away with using this more crude, yet quite fast method of collision detection. For games where your graphics are very squared off and pixel-perfect accuracy isn't a must, you can employ this command to do quick and dirty overlap checking.
<br />
-
<br />
- The example blatently uses graphics that are much smaller than their container to show you how inaccurate this command can be - if not used wisely. The ImagesCollide example is identical to this one - and shows how pixel-perfect collision works.
<br />
-
<br />
- You might be able to get away with this on some more classical games like Robotron, Defender, Dig Dug, etc.
- </td>
- </tr>
- </table>
- <h1><a href=../2d_examples/ImagesOverlap.bb>Example</a></h1>
- <table>
- <tr>
- <td>
- ; ImagesOverlap Example
<br />
-
<br />
- ; Turn on graphics mode
<br />
- Graphics 640,480,16
<br />
-
<br />
- ; Create two new empty graphics to store our circle and box in
<br />
- gfxBox=CreateImage(50,50)
<br />
- gfxCircle=CreateImage(50,50)
<br />
-
<br />
- ; Draw the box image first
<br />
- ; Set drawing operations to point to our new empty graphic
<br />
- SetBuffer ImageBuffer(gfxBox)
<br />
- ; Change drawing color to blue
<br />
- Color 0,0,255
<br />
- ;Draw our box (note that it has a 10 pixel space around it)
<br />
- Rect 10,10,30,30,1
<br />
-
<br />
- ; Repeat for the circle graphic
<br />
- SetBuffer ImageBuffer(gfxCircle)
<br />
- Color 255,0,0
<br />
- ; Note the extra space between the circle and the edge of the graphic
<br />
- Oval 10,10,30,30,1
<br />
-
<br />
- ; Let's not forget to put the drawing buffer back!
<br />
- SetBuffer BackBuffer()
<br />
-
<br />
- ; Locate our box to a random, visible screen location
<br />
- boxX=Rnd(50,610)
<br />
- boxY=Rnd(50,430)
<br />
-
<br />
- ; Repeat the loop until we've had a collision
<br />
- Repeat
<br />
- ; Attach our mouse to the circle to move it
<br />
- circleX=MouseX()
<br />
- circleY=MouseY()
<br />
- ; Standard double buffer technique; clear screen first
<br />
- Cls
<br />
- ; Draw our objects at the designated location
<br />
- DrawImage gfxBox,boxX,boxY
<br />
- DrawImage gfxCircle,circleX,circleY
<br />
- ; Standard double buffer technique; flip after all drawing is done
<br />
- Flip
<br />
- ; We test the locations of our box and circle to see if they have overlapped
<br />
- Until ImagesOverlap (gfxBox,boxX,boxY,gfxCircle,circleX,circleY)
<br />
-
<br />
- ; Loop is over, we must've collided!
<br />
- Text 0,0, "WE'VE HAD A COLLISION! PRESS A MOUSE BUTTON"
<br />
- ; Can't see the text until we flip ..
<br />
- Flip
<br />
- ; Wait for a mouse click
<br />
- WaitMouse()
<br />
- ; End our graphics mode
<br />
- EndGraphics
<br />
- </td>
- </tr>
- </table>
- <br>
- <a target=_top href=../index.htm>Index</a><br>
- <br>
- Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=ImagesOverlap&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
- </html>
|