crazy cursor - why?

BlitzPlus Forums/BlitzPlus Programming/crazy cursor - why?

hpb(Posted 2003) [#1]
Hi
Why does the following code work in blitz3d and not in blitz+.

[Edit] Sorry this was the wrong code, see my post beneath.

In blitz+ the cursor plays crazy.
Does somebody know why?

HP


okee(Posted 2003) [#2]
for a start the line
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
is within the loop so it's going to move to that position every time it loops hence the crazy movement.


hpb(Posted 2003) [#3]
Sorry I'm an idiot :-)
I had two code snippets (from friends) and took the wrong one. The following is the code with the really crazy cursor movement.

Graphics 800,600,16,1
SetBuffer BackBuffer()

Repeat
mausxspeed = 0
mausyspeed = 0
mausxspeed = MouseXSpeed()
mausyspeed = MouseYSpeed()
Text 500,200,mausxspeed
Text 500,300,mausyspeed
FlushMouse
If mausxspeed < -12 Then mausxspeed = -12
If mausxspeed > 12 Then mausxspeed = 12
If mausyspeed < -12 Then mausyspeed = -12
If mausyspeed > 12 Then mausyspeed = 12
MoveMouse oldx+mausxspeed,oldy+mausyspeed
oldx = MouseX()
oldy = MouseY()
Rect MouseX()-2,MouseY()-2,5,5,1
Flip
Cls
Until KeyDown(1)
End

Sorry for the inconvenience. Hope someone can help me with this one. Thanks okee for your answer.

HP


cyberseth(Posted 2003) [#4]
It's to do with this:
Graphics 800,600;,16,1 
SetBuffer BackBuffer() 

Repeat
Cls
x=x+1
MoveMouse x,10
Text 10,10,MouseXSpeed()
Flip

Until KeyDown(1) 
End


Even though you don't move the mouse manually, because the mouse is being moved by "MoveMouse", the MouseXSpeed is updated as 1 each frame. This is not the same in Blitz3D and I don't know why. But suffice to say you'll need to work that into your code. When you call MoveMouse, the MouseXspeed/MouseYSpeed are updated to account for the new mouse position!!


Pepsi(Posted 2003) [#5]
Also note that even the documentation for MouseXspeed/MouseYSpeed notes that you should call these commands twice in your loop. The second call should "zero" them out. Keep your current MouseXspeed/MouseYSpeed in where it is and try also putting:

mausxspeed = MouseXSpeed() 
mausyspeed = MouseYSpeed() 


again, right before the flip command and see if that helps out any.

And to continue off off what cyberseth said... the problem with your code above is that the variables mausxspeed & mausyspeed will always keep the last mouse movement difference even if you are not moving the mouse. So the positive or negative number will continuely move your rect cursor about the screen until it hits a screen border. The need for the second set of MouseXSpeed() and MouseYSpeed() is needed at the end of the loop, before flip, to zero the data MouseXSpeed()/MouseYSpeed() out. So when that second set is there and when you dont move the mouse, there shouldn't be any "crazy" movements involved.

Hope this helps...


hpb(Posted 2003) [#6]
Thanks a lot, this helps.
I also had to put a timer into the loop otherwise the mouse movement becomes snatchy.

HP


cyberseth(Posted 2003) [#7]
Better yet, Pepsi, put the second MouseX/YSpeed just after the MoveMouse command, so that if the user moves the mouse any time between then and the Flip, it doesn't get cancelled out.


Pepsi(Posted 2003) [#8]
Good call, cyberseth! :D