click menu???????

BlitzPlus Forums/BlitzPlus Programming/click menu???????

B_Paulie(Posted 2006) [#1]
i made a menu for my game, right now, its only start & quit. when you click on the one that is listed in the program first, its fint, but for the one that is checked secons, you have to click on the exact sreen coordnates. this is what it is
If ImagesOverlap(cross,MouseX(),MouseY(),start,512,300) And MouseHit (1) Then
game()
EndIf
If ImagesOverlap(cross,MouseX(),MouseY(),quit,512,700) And MouseHit (1) Then
End
EndIf

"i don't know how to do that thing where the code is black & green"


B_Paulie(Posted 2006) [#2]
example: start works when you click on the image
quit works when you click on the exact position of the image (512,700) instead of the whole image. HELP PLEASE


Grey Alien(Posted 2006) [#3]
based on the code you have posted, if it appears exactly like that, the only logical explanation is that quit is a 1x1 pixel image OR that you have made a mistake somewhere else in code you haven't posted. Also I would read the state of the mouse hit into a variable at the start so the mousehit function doesn't clear the input buffer when first tested. Then use the variable to check the state of the button in each IF statement. You could also use Else between each If statement to clarify things but you'll end up with a lot of indenting, to be honest I don't always bother either.

I never thought of doing ImagesOverlap, makes sense, I always read in the mouseX and Y into two variables (mx, my)at the start of each frame and then do:

If mx >= menux and mx < menux + imagewidth(menu) and my >=menuy and my < menuy + imageheight(menu) then

same thing really.

It's possible "quit" isn't the correct variable name I guess too, although I don't know (without testing) if ImagesOverlap would crash if given a null image (variable = 0).


WolRon(Posted 2006) [#4]
I'm sure his problem is the double usage of the MouseHit command.


Grey Alien(Posted 2006) [#5]
yeah the double use of the mousehit command is not a good thing but as for why only on one pixel, that's weird, unless he's misreporting by accident.


B_Paulie(Posted 2006) [#6]
ok , im sounding really dumb, but how do you put the mousex() and mousey() into a variable?


Pineapple(Posted 2006) [#7]
mx=MouseX()


B_Paulie(Posted 2006) [#8]
o, ok hehehehe


Buggy(Posted 2006) [#9]
Hmm... I've run into similar problems with mousehit, while mousedown seems to do the trick, and for a noobie like me, I'm stumped.


WolRon(Posted 2006) [#10]
You have to place the MouseHit() command into a variable if you intend on performing checks on it every time.

Remember, the ????Hit() commands clear their buffers once you use them even once.

in my programming tutorial, I comment on this in several of my example programs like so:

	;Collect user input
	upkey = KeyDown(200)	;up arrow		;It's a good practice to collect these inputs only once
	downkey = KeyDown(208)	;down arrow		; per loop.  This will prevent odd behaviors from happening,
	leftkey = KeyDown(203)	;left arrow		; for instance if the state of a key changes between multiple
	rightkey = KeyDown(205)	;right arrow		; checks of that key while still in the same loop.
	jumpkey = KeyDown(57)	;spacebar
	fastkey = KeyDown(42)	;left shift key
	
	If rightkey					;Check if the right key is being pressed
		If fastkey				;Check if the fast key is also being pressed
			xmove = 8			; if so, then attempt to move 8 pixels
		Else	
			xmove = 4			; if not, then only attempt to move 4 pixels
		EndIf
	EndIf
	If leftkey					;Check if the left key is being pressed
		If fastkey				;Check if the fast key is also being pressed
			xmove = -8			; if so, then attempt to move -8 pixels
		Else
			xmove = -4			; if not, then only attempt to move -4 pixels
		EndIf
	EndIf
Notice that I checked the fast key twice? This works because my variable will not change its value between my If statements. However, if I had checked the key directly, the user could have let go of the fast key between my two If statements.