Mouse click on image

BlitzMax Forums/BlitzMax Beginners Area/Mouse click on image

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This example uses a 'dummy' single-pixel image for testing collisions under the mouse.

There is no need to move or draw the dummy image. Just tell ImagesCollide() where the cursor is in relation to the image to test against:

' Mouse over image

Graphics 640,480,0,SOFTSYNC

' create a circle test image
Local image=CreateImage(64,64,1,DYNAMICIMAGE|MASKEDIMAGE)
Cls ; DrawOval 0,0,64,64 ; GrabImage image,0,0

' create a single pixel dummy image
dummyCursorImage=CreateImage(1,1,1,DYNAMICIMAGE|MASKEDIMAGE)
Plot 0,0 ; GrabImage dummyCursorImage,0,0


Repeat
	Cls
	mx=MouseX() ; my=MouseY()
	' draw the circle image
	DrawImage image,200,100
	' test for collision against dummy image
	result=ImagesCollide(image,200,100,0 , dummyCursorImage,mx,my,0)
	DrawText "Collision = "+Mid$("NO YES",result*4,3) , 10,10
	Flip
	FlushMem
Until KeyHit(KEY_ESCAPE)

End