issue with mousedown

Blitz3D Forums/Blitz3D Beginners Area/issue with mousedown

coffeeaddict(Posted 2011) [#1]
Here is a code snippet...

While Not KeyDown(key_esc)
	If KeyDown(key_left) Then HidePointer Else ShowPointer
	If MouseDown(1) Then HidePointer Else ShowPointer
	RenderWorld
	Flip
Wend


When I hold down the left key the pointer disappears and when I let it go, the pointer reappears (just as intended). When I try to do the same with the left mouse, the same thing does not work. Please let me know what I am doing wrong here.


Matty(Posted 2011) [#2]
I think you have your description around the wrong way but try this:

while not keydown(key_esc)
	if keydown(key_left) or mousedown(1) then hidepointer else showpointer
	renderworld
	flip
wend



Ross C(Posted 2011) [#3]
Just out of curosity, what happens when you put the mousedown line above the keydown line?


Foppy(Posted 2011) [#4]
It won't work correctly because the result of the second check will affect the result of the first check. If you press the key, HidePointer is called. However, right after that you check the mouse button; if it is not pressed, ShowPointer is called, doing away with the result of pressing the key.

Matty's solution should work because the two checks are combined into one using "or".

Last edited 2011


coffeeaddict(Posted 2011) [#5]
That does not work either. Here I commented out the if statement with the KeyDown and it still does not work...

While Not KeyDown(key_esc)
	;If KeyDown(key_left) Then HidePointer Else ShowPointer
	If MouseDown(1) Then HidePointer Else ShowPointer
	RenderWorld
	Flip
Wend



coffeeaddict(Posted 2011) [#6]
Hmm. I think I isolated the problem (HidePointer and ShowPointer don't seem to like MouseDown for some reason). However, this works:

While Not KeyDown(key_esc)
	If MouseDown(1) Then MouseDown0$="held down" Else MouseDown0$="not held down"
	RenderWorld
	Text 30,30,MouseDown0,False,False
	Flip
Wend


I guess I'll just keep the default pointer hidden and make my own using a sprite.


Warner(Posted 2011) [#7]
It seems that you can't change the mouse visibility while holding a mousebutton down. I tried api_SetCursor as well, but it doesn't seem to offer a solution either. Your solution of not using the default pointer seems to be a good workaround.


Matty(Posted 2011) [#8]
I tried it in blitzplus and it works fine, I guess it doesn't work in blitz3d.


jfk EO-11110(Posted 2011) [#9]
Regardless of what Warner said about this DX problem:
I think continous ShowPointer when nothing was hit is a little bit of a bad habit. What you got here is a classical flipflop situation. Use a flipflop-variable and hide the pointer accordingly. Additionally use a state-variable since there is no PointerHidden() function.

phid=0 ; pointer hidden?
hp=0 ; mouse or key down?

While Not KeyDown(key_esc)
	hp=0
	If KeyDown(key_left) Then hp=1
	If MouseDown(1) Then hp=1

	if phid=0 and hp=1 then: hidepointer():phid=1:endif
	if phid=1 and hp=0 then: showpointer():phid=0:endif

	RenderWorld
	Flip
Wend


edit: i just realize there is indeed a bug, preventing the mouse from being hidden while a button is pressed.

Last edited 2011