Code archives/Miscellaneous/MouseXSpeed() / MouseYSpeed()
This code has been declared by its author to be Public Domain code.
Download source code
| I miss simple pleasures like MouseXSpeed so I knocked this up. I'll be doing a few more things like this to make my life easier in BMax.|
EDIT: Just realized it's all integers so I took out all the Floats.
'MouseSpeed Setup Global MouseXSpeed:Int 'MouseXSpeed() Component Global MouseYSpeed:Int 'MouseYSpeed() Component Global CenterX:Int = GraphicsWidth() / 2 'Find CenterX Global CenterY:Int = GraphicsHeight() / 2 'Find CenterY MoveMouse CenterX,CenterY 'Move Mouse to Center of Screen Function MouseSpeed() Local XM:Int = MouseX() Local YM:Int = MouseY() MouseXSpeed = XM - CenterX MouseYSpeed = YM - CenterY MoveMouse CenterX,CenterY End Function
| Here's the test code to it. Hope someone finds this useful like me.|
'Test Program Graphics 800,600,0 include "MouseSpeed.bmx" Local x:Float Local y:Float While Not KeyHit(KEY_ESCAPE) Cls MouseSpeed() 'Call This Every Cycle 'Move a "+" around with MouseSpeed x=x+MouseXSpeed y=y+MouseYSpeed DrawText "+",x,y Flip Wend
| http://www.blitzbasic.com/Community/posts.php?topic=47133 |
| Wish someone had put that in the archives like it should have been. :\ |
| sorry, I never thought it was that useful to people. :\ |
| This didn't work so I rewrote it. I don't know what Chroma was trying to do so I took a guess, it's a + that trails the mouse around. Uses code from here.|
' Test 'Rem Graphics 640,480,0 Local mouse:TMouse = New TMouse While Not (KeyHit(KEY_ESCAPE) + AppTerminate()) Cls DrawText "+", mouse.Trailx, mouse.Traily ' draw mouse trail DrawText "Xspeed: " + mouse.XSpeed(), 10, 10 DrawText "Yspeed: " + mouse.YSpeed(), 10, 25 DrawText "Trailx: " + mouse.Trailx, 10, 40 DrawText "Traily: " + mouse.Traily, 10, 55 mouse.Update() Flip Wend 'EndRem ' Mouse Trail.bmx ' A modified version of TMouse type by GfK Type TMouse Field lastx:Int Field lasty:Int Field Trailx:Int Field Traily:Int Method New() ' init trail Trailx = GraphicsWidth() / 2 ' center of screen Traily = GraphicsHeight() / 2 MoveMouse(Trailx, Traily) ' center the mouse Trailx :+ 4 ' reposition below mouse pointer Traily :+ 22 lastx = MouseX() ' get new mouse position lasty = MouseY() End Method Method XSpeed:Int() ' was MouseXSpeed() Return MouseX() - lastx End Method Method YSpeed:Int() ' was MouseYSpeed() Return MouseY() - lasty End Method Method Update() Trailx :+ MouseX() - lastx Traily :+ MouseY() - lasty lastx = MouseX() lasty = MouseY() End Method End Type
Code Archives Forum
|Blitz Social Club|