Blitz3D+ Command Reference

MouseYSpeed ( )

Parameters

None.

Description

Returns how far the mouse has moved vertically since the last time you asked.

It is the vertical half of mouse-look. Read it once a frame alongside MouseXSpeed, turn the camera by the values, and warp the pointer back to the centre of the screen with MoveMouse so it never runs out of desk. Positive means the mouse moved down the screen, so most games negate it - or offer an "invert look" option that does.

The value is the difference since your previous call to this same command, not since the previous frame. Call it once per loop. Calling it twice in a row makes the second call report almost nothing, and skipping frames means the movement piles up until you next read it.

For pitch you usually want to clamp the total rather than the step, so the camera cannot roll over backwards: add the value to an angle, then limit that angle to about plus or minus 90 degrees.

Gotcha: the first call after startup, or after the window regains focus, may report a large jump as the reference point catches up - read and throw one value away when you enter mouse-look. MoveMouse updates the reference point too, so recentring the pointer does not add a phantom step of its own.

See also: MouseXSpeed, MouseZSpeed, MouseY, MoveMouse, HidePointer.

Example

; MouseYSpeed Example
; -------------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; Hide the Windows pointer - we steer with movement deltas instead
HidePointer

aim_x#=320
aim_y#=240

While Not KeyDown(1)

    Cls

    ; MouseYSpeed returns how far the mouse moved vertically since
    ; the last call (MouseXSpeed is its horizontal partner).
    ys=MouseYSpeed()
    xs=MouseXSpeed()

    ; FPS-style aiming: re-centre the pointer every frame and steer
    ; the crosshair with the deltas - the pointer itself can never
    ; get stuck at the edge of the screen.
    MoveMouse 320,240

    aim_x=aim_x+xs
    aim_y=aim_y+ys

    ; Wrap the crosshair at the window edges
    If aim_x<0 Then aim_x=aim_x+640
    If aim_x>639 Then aim_x=aim_x-640
    If aim_y<0 Then aim_y=aim_y+480
    If aim_y>479 Then aim_y=aim_y-480

    ; Crosshair
    Color 255,255,0
    Oval aim_x-10,aim_y-10,20,20,False
    Line aim_x-14,aim_y,aim_x+14,aim_y
    Line aim_x,aim_y-14,aim_x,aim_y+14

    Color 255,255,255
    Text 0,0,"Move the mouse to drift the crosshair (no screen edges)   Esc: exit"
    Text 0,20,"MouseYSpeed() this frame: "+ys
    Text 0,40,"MouseXSpeed() this frame: "+xs

    Flip

Wend

End

Index