pods::...terface(3pm)
πΈ NAME πΈ
okay bestie, this is the pods::...terface(3pm) page from the User Contributed Perl Documentation, and it's literally about SDLx::Controller::Interface β Interface Physics and Rendering with the Controller with callbacks. no cap, that's the whole name π
π·οΈ CATEGORY π·οΈ
Extension, Controller
β¨ SYNOPSIS β¨
here's the vibe in code form, bestie π«Ά
use SDL;
use SDLx::App;
use SDLx::Controller::Interface;
#SDLx::App is a controller
my $app = SDLx::App->new(width => 200, height => 200 );
my $ball = SDLx::Controller::Interface->new( x=> 10, y => 50, v_x => 10, v_y=> 20 );
#Set the initial state of the ball's physics, this is optional
$ball->set_acceleration(
sub {
my ($time, $current_state) = @_;
return( 0, -10, 0 ); # Return accelerations (x,y,rotation)
}
);
my $ball_render = sub {
my $state = shift;
$app->draw_rect( undef, 0 );
$app->draw_rect( [$state->x, $state->y, 10,10], [255,0,0,255] );
$app->update();
};
$ball->attach( $app, $ball_render, @params );
$app->run();
$ball->detach(); #can be called at anytime (for example when ball 'dies')
π DESCRIPTION π
okay so the original DESCRIPTION section is literally empty, bestie β no extra prose to spill here, so we're moving straight to the methods. main character energy only πβ¨
π οΈ METHODS π οΈ
π set_acceleration π
Allows you to set the acceleration callback for defining the interface's behaviour in terms of x,y and rotation.
$interface->set_acceleration (
sub {
my ($time, $current_state) = @_;
return ( $accel_x, $accel_y, $torque );
}
);
These accelerations are arbitrary and can be set to any frame of reference. Your render callback will handle how to interpret it. iykyk π
The callback will receive the time and the current state as a SDLx::Controller::State element.
π«Ά attach π«Ά
Attaches the interface to a controller with a render callback.
$interface->attach( $controller, $render, @params );
Where $render is a callback that receives the interpolated SDLx::Controller::State.
my $render = sub {
my ($state, @params) = @_;
# draw the current $state.
};
The @params are any extra parameters you would like to pass to the $render callback. cute, flexible, slay β¨
π current π
my $current_state = $interface->current();
Returns the current state of the interface as a SDLx::Controller::State.
βͺ previous βͺ
my $previous_state = $interface->previous();
Returns the previous state of the interface as a SDLx::Controller::State.
π detach π
$interface->detach();
If $interface has been attach()'ed to any controller it will be detached now.
π¨ OTHER METHODS π¨
Don't use these unless you really really want to.
fr fr, that's the warning, bestie β these are the danger-adjacent extra methods π
β‘ acceleration β‘
Call the acceleration callback once.
π§΅ interpolate π§΅
Interpolate the current state.
π§ͺ evaluate π§ͺ
Evaluate the new current and previous state.
π update π
Update the states by integrating with time.
π AUTHORS π
See "AUTHORS" in SDL.
that's it, bestie π«Ά this page came from perl v5.42.0, dated 2024-05-01 β mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-SDL 2.548-bp160.1.13 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms