MouseHit() and FlushMouse Question!

BlitzPlus Forums/BlitzPlus Programming/MouseHit() and FlushMouse Question!

SopiSoft(Posted 2003) [#1]
At the moment i'm working on a BlackJack Card game, that has several buttons you can click on in order to act upon the situation you're in.

The problem is that whenever i click in a region outside the buttons, there is a mouseclick in the queue, and then when i move over a button the code in the "If ImagesOverlap()" statement is executed.

At the moment i can sort of handle this problem by using FlushMouse every second, but do you guys know a better way to solve this problem?

This is what i use:
If ImagesOverlap(btn,100-15,GraphicsHeight()-(ImageHeight(btn)*2)+10,pointer,MouseX(),MouseY())
		
	DrawImage btn_o,100-15,GraphicsHeight()-(ImageHeight(btn)*2)+10
			
	If MouseHit(1)
		PlaySound clicksnd
		;rest of the code
	EndIf
					
			
Else
			
	DrawImage btn,100-15,GraphicsHeight()-(ImageHeight(btn)*2)+10
					
			
EndIf



and this is what i do every frame to clear the Mousehit queue:

If MilliSecs() > timer+1000
    timer=MilliSecs()
    FlushMouse
EndIf


I hope you guys know a better way...:)


keyboard(Posted 2003) [#2]
try this code and put your own sound in



Graphics 800,600

ClickSound = LoadSound("YOUR_SOUND_HERE")

ButtonImage1 = CreateImage(100,30)
SetBuffer ImageBuffer(ButtonImage1)
Color 200,51,51
Rect 0,0,100,30

ButtonImage2 = CreateImage(100,30)
SetBuffer ImageBuffer(ButtonImage2)
Color 51,200,51
Rect 0,0,100,30

PointerImage = CreateImage(10,10)
SetBuffer ImageBuffer(PointerImage)
Color 51,51,255
Rect 0,0,10,10


SetBuffer BackBuffer()

Global MyMouseHit

While Not KeyHit(1)

	MyMouseHit = MouseHit(1)
	
	DrawImage PointerImage,MouseX(),MouseY()
		
	If ImagesOverlap(ButtonImage1,100,100,PointerImage,MouseX(),MouseY())			
		DrawImage ButtonImage2,100,100				
		If MyMouseHit = 1 Then
			PlaySound ClickSound
			;rest of the code
		EndIf			
	Else				
		DrawImage ButtonImage1,100,100				
	EndIf
	
	Flip

Wend

FreeImage ButtonImage1
FreeImage ButtonImage2
FreeImage PointerImage
FreeSound ClickSound

End






SopiSoft(Posted 2003) [#3]
this works just the way i wanted it to work!!! :-D
Thanx a lot m8!!! ;-D