.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "pods::SDL::Joystick 3pm" .TH pods::SDL::Joystick 3pm 2024-03-28 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME SDL::Joystick \-\- SDL Bindings for the Joystick device .SH CATEGORY .IX Header "CATEGORY" Core, Joystick .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use SDL; \& use SDL::Joystick; \& \& SDL::init_sub_system(SDL_INIT_JOYSTICK); \& \& die(\*(Aqno joystick found\*(Aq) unless(SDL::Joystick::num_joysticks()); \& \& my $joystick = SDL::Joystick\->new(0); .Ve .SH METHODS .IX Header "METHODS" .SS num_joysticks .IX Subsection "num_joysticks" .Vb 1 \& int SDL::Joystick::num_joysticks( void ); .Ve .PP Counts and returns available joysticks. .SS name .IX Subsection "name" .Vb 1 \& string SDL::Joystick::name( index ); .Ve .PP Get the implementation dependent name of joystick. The \f(CW\*(C`index\*(C'\fR parameter refers to the N'th joystick on the system. .PP .Vb 1 \& my $num_joysticks = SDL::Joystick::num_joysticks(); \& \& printf("%d joysticks found\en", $num_joysticks); \& \& for($i = 0; $i < $num_joysticks; $i++) \& { \& printf("%s\en", SDL::Joystick::name($i)); \& } .Ve .SS new .IX Subsection "new" .Vb 1 \& object SDL::Joystick\->new( index ); .Ve .PP Opens a joystick for use within SDL. The \f(CW\*(C`index\*(C'\fR refers to the N'th joystick in the system. A joystick must be opened before it can be used. .PP .Vb 2 \& # Initialize the joystick subsystem \& SDL::init_sub_system(SDL_INIT_JOYSTICK); \& \& # Check for joystick \& if(SDL::Joystick::num_joysticks() > 0) \& { \& # Open joystick \& my $joystick = SDL::Joystick\->new(0); \& \& if($joystick) \& { \& printf("Opened Joystick 0\en"); \& printf("Name: %s\en", SDL::Joystick::name(0)); \& printf("Number of Axes: %d\en", SDL::Joystick::num_axes($joystick)); \& printf("Number of Buttons: %d\en", SDL::Joystick::num_buttons($joystick)); \& printf("Number of Balls: %d\en", SDL::Joystick::num_balls($joystick)); \& } \& else \& { \& printf("Couldn\*(Aqt open Joystick 0\en"); \& } \& \& # Close if opened \& SDL::Joystick::close($joystick) if SDL::Joystick::opened(0); \& } .Ve .SS opened .IX Subsection "opened" .Vb 1 \& int SDL::Joystick::opened( index ); .Ve .PP Determines whether a joystick has already been opened within the application. \f(CW\*(C`index\*(C'\fR refers to the N'th joystick on the system. .PP Returns 1 if the joystick has been opened, or 0 if it has not. .SS index .IX Subsection "index" .Vb 1 \& int SDL::Joystick::index( object ); .Ve .PP Returns the \f(CW\*(C`index\*(C'\fR of a given \f(CW\*(C`SDL_Joystick\*(C'\fR structure. See SDL::Joystick::new .SS num_axes .IX Subsection "num_axes" .Vb 1 \& int SDL::Joystick::num_axes( object ); .Ve .PP Return the number of axes available from a previously opened joystick. See SDL::Joystick::new .SS num_balls .IX Subsection "num_balls" .Vb 1 \& int SDL::Joystick::num_balls( object ); .Ve .PP Return the number of trackballs available from a previously opened joystick. See SDL::Joystick::new .SS num_hats .IX Subsection "num_hats" .Vb 1 \& int SDL::Joystick::num_hats( object ); .Ve .PP Gets the number of joystick hats from a previously opened joystick. See SDL::Joystick::new .SS num_buttons .IX Subsection "num_buttons" .Vb 1 \& int SDL::Joystick::num_buttons( object ); .Ve .PP Gets the number of joystick buttons from a previously opened joystick. See SDL::Joystick::new .SS update .IX Subsection "update" .Vb 1 \& void SDL::Joystick::update(); .Ve .PP Updates the state(position, buttons, etc.) of all open joysticks. If joystick events have been enabled with \f(CW\*(C`SDL::Joystick::event_state\*(C'\fR then this is called automatically in the event loop. .SS get_axis .IX Subsection "get_axis" \&\f(CW\*(C`get_axis\*(C'\fR returns the current state of the given axis on the given joystick. .PP On most modern joysticks the X axis is usually represented by axis 0 and the Y axis by axis 1. The value returned by \f(CW\*(C`get_axis\*(C'\fR is a signed integer (\-32768 to 32767) representing the current position of the axis, it may be necessary to impose certain tolerances on these values to account for jitter. .PP \&\fBNote\fR: Some joysticks use axes 2 and 3 for extra buttons. .PP Returns a 16\-bit signed integer representing the current position of the axis. .PP .Vb 1 \& my $joystick = SDL::Joystick\->new(0); \& \& my $x_move = SDL::Joystick::get_axis($joystick, 0); \& my $y_move = SDL::Joystick::get_axis($joystick, 1); .Ve .SS get_hat .IX Subsection "get_hat" .Vb 1 \& int SDL::Joystick::get_hat( object, int ); .Ve .PP \&\f(CW\*(C`get_hat\*(C'\fR returns the current state of the given \f(CW\*(C`hat\*(C'\fR on the given \f(CW\*(C`joystick\*(C'\fR. .PP The current state is returned which is an OR'd combination of one or more of the following: .IP \(bu 4 \&\f(CW\*(C`SDL_HAT_CENTERED\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`SDL_HAT_UP\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`SDL_HAT_RIGHT\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`SDL_HAT_DOWN\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`SDL_HAT_LEFT\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`SDL_HAT_RIGHTUP\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`SDL_HAT_RIGHTDOWN\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`SDL_HAT_LEFTUP\*(C'\fR .IP \(bu 4 \&\f(CW\*(C`SDL_HAT_LEFTDOWN\*(C'\fR .PP .Vb 1 \& my $joystick = SDL::Joystick\->new(0); \& \& my $position = SDL::Joystick::get_hat($joystick, 0); \& \& print("hat is in position UP\en") if $position & SDL_HAT_UP; .Ve .SS get_button .IX Subsection "get_button" .Vb 1 \& int SDL::Joystick::get_button( object, int ); .Ve .PP \&\f(CW\*(C`get_button\*(C'\fR returns the current state of the given button on the given joystick. .PP Returns 1 if the button is pressed. Otherwise, 0. .PP .Vb 1 \& my $joystick = SDL::Joystick\->new(0); \& \& my $num_buttons = SDL::Joystick::num_buttons($joystick); \& \& for(my $i = 0; $i < $num_buttons; $i++) \& { \& printf("button %d is %s\en", $i, SDL::Joystick::get_button($joystick, $i) ? \*(Aqpressed\*(Aq : \*(Aqnot pressed\*(Aq); \& } \& \& SDL::Joystick::close($joystick) if SDL::Joystick::opened(0); .Ve .SS get_ball .IX Subsection "get_ball" .Vb 1 \& int SDL::Joystick::get_ball(SDL_Joystick $joystick, int $ball, int $dx, int $dy); .Ve .PP Get the ball axis change. .PP Trackballs can only return relative motion since the last call to SDL::Joystick::get_ball, these motion deltas are placed into \f(CW\*(C`dx\*(C'\fR and \f(CW\*(C`dy\*(C'\fR. .PP Returns 0 on success or \-1 on failure .PP .Vb 3 \& my $delta_x = 0; \& my $delta_y = 0; \& my $joystick = SDL::Joystick\->new(0); \& \& SDL::Joystick::update(); \& \& printf("TrackBall Read Error!\en") if(SDL::JoystickGetBall($joystick, 0, $delta_x, $delta_y) == \-1); \& printf("Trackball Delta\- X:%d, Y:%d\en", delta_x, delta_y); .Ve .SS close .IX Subsection "close" .Vb 1 \& void SDL::Joystick::close( object ); .Ve .PP Closes a previously opened joystick. See SDL::Joystick::new .PP .Vb 1 \& SDL::Joystick::close($joystick) if SDL::Joystick::opened(0); .Ve .SH AUTHORS .IX Header "AUTHORS" See "AUTHORS" in SDL.