Allegro::Joystick - Allegro joystick routines
use Allegro;
$al = Allegro->new();
$joy = $al->Joystick() or die;
$b = $joy->buttons; $s = $joy->sticks;
print "joystick as $b buttons, $s sticks.\n";
print "Hit button 1\n";
while(!$joy->button(0)) { }
while(1)
{
($x, $y) = $joy->position(0);
($b0, $b1) = $joy->button;
print "x=$x y=$y b0=$b0 b1=$b1\n";
sleep 1;
}
Allegro::Joystick is an interface to the Allegro joystick routines.
Polling is required, but will be done automatically by the button and position methods.
$joy = $al->Joystick(joystick => 0,
mode => 'digital');
Returns an Allegro::Joystick object on success, or undef otherwise.
new() will return an object
corresponding to the next available joystick, or undef if no more are
available.
$a = $joy->axes(0); # Number of axes on stick 0.
Defaults to the first stick.
$name = $joy->button_name(0); @names = $jot->button_name;
$name = $joy->stick_name(0); @names = $joy->stick_name;
$name = $joy->axis_name(I<stick>, 0); @names = $joy->axis_name(I<stick>);
$joy->poll;
Polls the joystick driver and updates the object's internal data. This will be called automatically by button and position, but is required to be done manually to access the object directly.
This will automatically poll the joystick driver.
$b1 = $joy->button(0); $b2 = $joy->button(1);
This allows access to a certain button on the joystick.
@buttons = $joy->button;
This allows access to all buttons at once, in an array.
This will automatically poll the joystick driver.
The first argument is the stick number and the second is the axis number.
$lr = $joy->position(0, 0); $ud = $joy->position(0, 1);
Set $lr to the left/right position and $ud to the up/down position.
@s1 = $joy->position(0);
Returns an array containing the position of all the axes on the first stick.
@s = $joy->position;
Returns an array of array references containing position information for each stick/axis combination.
Colin O'Leary <colin@mx3.org>
Copyright 2003 by Colin O'Leary. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The Allegro library is copyright its authors, and is giftware. See http://alleg.sf.net for more information.