Did update change MouseXSpeed and MouseYSpeed?

Archives Forums/BlitzPlus Programming/Did update change MouseXSpeed and MouseYSpeed?

Abazek(Posted 2004) [#1]
I recently downloaded and installed BlitzPlus Update 137 (formerly had BlitzPlus 111).

Is there a Version Log which lists chages? Specifically, what was changed with the MouseXSpeed and MouseYSpeed functions?

I was using these fuctions to aim a tank turret in a game I'm making, and with BlitzPlus 111 it works fine. Now with the 137 updated installed, the turret jumps all over the place.

Here's the piece of code:

;; MouseX can also change gun angle
mxs=MouseXSpeed()
If mxs<>0 Then
tank\angle=tank\angle+mxs
MoveMouse ScreenXSize/2,ScreenYSize/2
End If

If I comment out the "MoveMouse" it works as before... But it will stop when the mouse hits the edge of the screen (that was why I put the MoveMouse in... It would keep the mouse in the center so it would never hit the edge of the screen and quit working).

I've thought of several solutions (I can share them if you want, just let me know).

I was just wondering what changes were made to MouseXSpeed() and MouseYSpeed() because the above code worked pefectly in BlitzPlus 111 but doesn't work in BlitzPlus 137 (nothing else was changed in the Source Code. Only change was to update to BlitzPlus 137)


Eikon(Posted 2004) [#2]
After you install an update, versions.txt is placed in your B+ directory and it outlines the fixes. I looked through my 1.37 changelog and didn't see any note of mouse alterations.


sswift(Posted 2004) [#3]
The mouse speed functions return the number of pixels the mouse has moved. Changing it would be nonsensical.

I'll bet you're just running your game, or windows, in a different resolution.

The solution is to code a custom mouse speed function which takes into account the resolution, assuming that windows does not change the mouse speed depending on resolution. I'm not sure if it does or not.

If it does, then using floating point values, divide the speed by the resolution, and either use that, or multiply by your chosen base resolution, ie, 1024x768, to convert to pixels in that res.

You can also average the mouse position over two frames to smooth out the motion more.


Abazek(Posted 2004) [#4]
Thanks for mentioning Versions.txt Eikon.

Also, good suggestions, sswift... But I'm not changing MouseSpeed. I'm changing MouseCoordinates!
This has to be done so MouseXSpeed will always return a value when the player moves the mouse (if I do not return
the mouse to the center afterwords, MouseXSpeed will always return 0 when the mouse reaches the edge of the screen. Even if the player continues to move it...)

Also, keep in mind that it worked perfectly in BlitzPlus 1.11, but it doesn't work in BlitzPlus 1.37... The only
thing that changed is that I updated BlitzPlus. Nothing else. Its the same machine, same Windows version, same
Resolution... I even rebooted to make sure it wasn't just Windows instability...

My solution, for now, was to Down-Grade... That is, to use the older BlitzPlus 1.11, which I had originally downloaded. I don't like that at all because there are a lot of Bug Fixes between 1.11 and 1.37!!!


PS: The code also works fine in Blitz3D 1.86 (the newest available at time of this writing). But I am planning to use a few functions which are present BlitzPlus but not in Blitz3D...


Eikon(Posted 2004) [#5]

But I'm not changing MouseSpeed. I'm changing MouseCoordinates!


SSwift meant that an update changing the command would be pointless, not you.

I just noticed MoveMouse has an optional canvas parameter just like MouseXSpeed()/MouseYSpeed(). If your even using one, have you tried passing them the canvas handle?


Abazek(Posted 2004) [#6]
I agree... I'm thinking its a BUG... Like maybe updating something else (perhaps the addition of Canvases?) might have inadvertantly caused MouseXspeed/MouseYspeed to behave differently.

In my code, I'm not using any canvas. Just GRAPHICS 800,600,16,1 and TEXT, PLOT, DRAWIMAGE, and FLIP. Pretty simple stuff.

Hmm... Wondering if there is a canvas handle for the default screen?


Oh, and thanks for your help and quick response!


Abazek(Posted 2004) [#7]
FOUND A FIX... If you add a call to MouseXSpeed IMMEDIATELY after the call to MoveMouse, it works correctly (in all versions old and new both BlitzPlus and Blitz3D).

This code illustrates:

.MainLoop
;;
;; Whole bunch of other code for the game here
;;
mxs=MouseXSpeed()
If mxs<>0 Then
tank\angle=tank\angle+mxs
MoveMouse ScreenXSize/2,ScreenYSize/2
mxs=MouseXSpeed()
End If
;;
;; Code to draw Tank, Turrent, and FLIP here...
;;
Goto MainLoop

Now if anyone can tell me WHY this extra call to MouseXSpeed is required in the newer (1.36, 1.37) versions of BlitzPlus and NOT required in the older (1.11) versions of BlitzPlus and the current version (1.86) of Blitz3D that would be great!!

PS: I got the idea to try this from the Blitz3D documentation. There's a line that says "You really have to use these commands TWICE to get anything out of them. Each call you make returns the difference in location since the LAST time you called it."...

Now, whats funny is in the example code given (in Blitz3D Documentation) does NOT call MouseXSpeed and MouseYSpeed immediately after the call to MouseMove... This example code (just like my code) will run just fine in BlitzPlus 1.11 but will not run correctly (as is) BlitzPlus 1.37. It will run in both older and newer versions of Blitz3D.

In the Sample Code, if you add a call to MouseXSpeed and MouseYSpeed immediately after the call the MoveMouse, the Sample Code will work in BlitzPlus 1.37.


DEFINITELY, UNQUESTIONABLY A BUG HERE SOMEWHERE. Either BlitzPlus 1.37 isn't handling MouseXSpeed/MouseYSpeed correctly (most likely), OR all the other versions of BlitzPlus and Blitz3D are not handling it correctly (unlikely).



Here is the Sample Code from the Blitz3D Docs, for reference
(this is the code without the extra calls after MoveMouse, it will work fine in Blitz3D and older versions of BlitzPlus, but not in newer versions of BlitzPlus):

Graphics 640,480
SetBuffer BackBuffer()
x=320
y=240

; infinite mouse movement

Repeat
Cls
xs=MouseXSpeed() ; see how far the mouse has been moved
ys=MouseYSpeed()
MoveMouse 320,240 ;put the mouse back in the middle of the screen

x=x+xs ;adjust mouse co-ords
y=y+ys

If x>GraphicsWidth()-1 Then x=x-GraphicsWidth() ;wrap screen
If x<0 Then x=x+GraphicsWidth()
If y<0 Then y=y+GraphicsHeight()
If y>GraphicsHeight()-1 Then y=y-GraphicsHeight()

Text x,y,"X",True,True

Flip
Until KeyHit(1)
End



Here is that same sample code with the extra call to MouseXSpeed and MouseYSpeed after the call to MoveMouse (this will work correctly in all versions of BlitzPlus and Blitz3D):

Graphics 640,480
SetBuffer BackBuffer()
x=320
y=240

; infinite mouse movement

Repeat
Cls
xs=MouseXSpeed() ; see how far the mouse has been moved
ys=MouseYSpeed()
MoveMouse 320,240 ;put the mouse back in the middle of the screen
;;
;; Extra call to MouseXSpeed/MouseYSpeed to overcome BUG in BlitzPlus 1.36 and 1.37:
;;
tmp=MouseXSpeed()
tmp=MouseYSpeed()

x=x+xs ;adjust mouse co-ords
y=y+ys

If x>GraphicsWidth()-1 Then x=x-GraphicsWidth() ;wrap screen
If x<0 Then x=x+GraphicsWidth()
If y<0 Then y=y+GraphicsHeight()
If y>GraphicsHeight()-1 Then y=y-GraphicsHeight()

Text x,y,"X",True,True

Flip
Until KeyHit(1)
End


Hopefully this will help others who want to use the Mouse to move game characters in BlitzPlus!


sswift(Posted 2004) [#8]
So... what you're doing is:

Get the mouse speed since the last time you called the function.

At this point the mouse is still off center.

Then you move the mouse back to the center of the screen.

Then getting the mouse speed again.

What this second mouse speed call is telling you is how far the mouse moved since the last call to it. And the mouse has just been moved from some location on the screen, back to the center.

At first glance I thought what you were doing was nonsensical, since the mouse couldn't have moved very far since you called the mouse position command, but apparently the mouse position command doesn't reset the mouse speed command back to 0.

I have to ask though... you have two calls there. Which is the original? The one before repositioning the mouse in the center, or the one after? Have you considered that you could just put the one in the other place? Ie, if it was before, put it after? That could solve your problem too.

I don't know why it would not work both ways.