The joystick is a useful component when you need
a succint way to let the users specify a vector (direction and magnitude).
The joystick's x,y
values (returned from events generated by the joystick) range from
-maxVal to maxVal,
with 0 being the center, in Cartesian coordinate space. The routines
allow the user to move the hot spot (knob) either by mouse or programmatically,
and then they rotate and scale the stick to the proper angle and
length, from 0 (at center pos) to its fully extended position at
maxVal (which the
user can set). The joystick generates pulses, at a given frequency
and any time the stick is moved, that report its position if it
is not at the center. A property, forceInt,
says whether to report the value as a floating point number or rounded
integer. The default event message is "JStickChg".
The joystick snaps back to the center when it released, and a "stickiness"
coefficient says how quickly this happens.
The hardest part about making the joystick is coming up with the
graphics to make it look good in all positions. We can't say we've
done that, but we gave it a shot. If you replace the existing graphics,
they should be set such that hot spot is in the topmost position
and the stick is fully extended upwards. The joystick uses these
pixel values to compute its possible range.
|