How do I slow down mouse movement in-game?
Blitz3D Forums/Blitz3D Beginners Area/How do I slow down mouse movement in-game?
| ||
Hi, I am currently working on a spaceshooter game where the player is controlled by moving the mouse around. Currently, I simply control the player like this. Function MovePlayer() Player\x = MouseX() Player\y = MouseY() End Function But when I move the player he just zips all over the screen do to my mouse speed. How can I slow down the speed of the mouse in-game, without messing up the speed of my mouse out of game? Do I have to use MoveMouse() and the MouseSpeed commands? (And perhaps some tricky math too?) Or is there an easier way to do this? The Mighty WERDNA(Lord Of Darkness) |
| ||
Wow, I can actually help someone else for a change! It's easy, you just put /2 after the mouseposition and mouseheight variables. That'll make it go half speed. You can make it anything. You could make it 1/40th normal speed, just write mouseposition/40. The variable must be a float though, since you're actually dividing a pixel into 40, or however many pieces. 40 is about what I used for when my characters were flying off screen at mach 4. http://h1.ripway.com/fox95871/index.html It's in this code somewhere. I'm not sure where right now cause I'm not at a computer where I can open it. It's a short file though, you should be able to find it pretty easily. Good luck, hope this helps! |
| ||
Wow! Thanks man! This should work perfectly ^_^ I'll check it out later and tell you how it worked. The Mighty WERDNA(Lord Of Darkness) |
| ||
Here is the MouseXSpeed and MouseYSpeed example.Graphics 640,480 SetBuffer BackBuffer() x=320 y=240 ; infinite mouse movement Repeat Cls xs=MouseXSpeed()/2 ; see how far the mouse has been moved ys=MouseYSpeed()/2 ; Just change the /2 for slower or faster mouse movement 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 |
| ||
MouseXSpeed() and MouseYSpeed() is really the way to go, as that identifies the change of position the mousecursor per call. Also, you may wish to re-position the cursor (MoveMouse) each loop too. If you have any frame-limiting or timing code, you can also include some delta code to get a proportional mousemovement per second or per tenth-of-second etc. whichever gives the omst 'playable' results. |