Blitz3D+ Command Reference

MouseZ ( )

Parameters

None.

Description

Returns the running total of mouse wheel notches since the program started.

There is no absolute "wheel position" on a mouse, so Blitz keeps a counter for you. It starts at 0, goes up by one for every notch rolled away from you and down by one for every notch rolled towards you. Wheel movement is counted in whole notches, matching the click you feel as the wheel turns.

Because it is a running total, the useful thing is usually the change rather than the number itself. Remember last frame's value and subtract, or let MouseZSpeed do it for you - that is the normal way to drive a weapon selector, a zoom level or a scrolling inventory.

Used directly, the total makes a fine control on its own: clamp it to a range and it becomes a zoom factor or a scroll offset that remembers where the player left it.

Gotchas: the wheel is only counted while your window has the focus, and losing focus resets the total to 0, so store the value you care about rather than assuming the counter is untouched. Not every mouse has a wheel, so keep a keyboard alternative for anything important.

See also: MouseZSpeed, MouseX, MouseY, MouseHit, FlushMouse.

Example

; MouseZ Example
; --------------

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

; Weapon rack for the scroll-wheel selector
Dim weapon$(3)
weapon$(0)="Blaster"
weapon$(1)="Spread gun"
weapon$(2)="Laser"
weapon$(3)="Rockets"

While Not KeyDown(1)

    Cls

    ; MouseZ returns the mouse wheel position: it starts at 0 and
    ; counts up as the wheel rolls away from you, down towards you.
    wheel=MouseZ()

    ; Wrap the wheel position onto the four weapon slots
    slot=wheel Mod 4
    If slot<0 Then slot=slot+4

    ; Draw the weapon rack, highlighting the selected slot
    For i=0 To 3
        If i=slot Then
            Color 255,220,0
            Rect 80+i*130,200,110,60,True
            Color 0,0,0
        Else
            Color 90,90,90
            Rect 80+i*130,200,110,60,False
            Color 255,255,255
        End If
        Text 135+i*130,230,weapon$(i),True,True
        Color 255,255,255
    Next

    Text 0,0,"Roll the mouse wheel to change weapon   Esc: exit"
    Text 0,20,"MouseZ() = "+wheel+"   selected slot: "+slot+" ("+weapon$(slot)+")"

    Flip

Wend

End

Index