1SDLx::Controller::InterUfsaecre(C3o)ntributed Perl DocumSeDnLtxa:t:iCoonntroller::Interface(3)
2
3
4

NAME

6       SDLx::Controller::Interface - Interface Physics and Rendering with the
7       Controller with callbacks
8

CATEGORY

10       Extension, Controller
11

SYNOPSIS

13        use SDL;
14        use SDLx::App;
15        use SDLx::Controller::Interface;
16
17        #SDLx::App is a controller
18        my $app = SDLx::App->new(width => 200, height => 200 );
19
20        my $ball = SDLx::Controller::Interface->new( x=> 10, y => 50, v_x => 10, v_y=> 20 );
21        #Set the initial state of the ball's physics, this is optional
22
23        $ball->set_acceleration(
24           sub {
25                     my ($time, $current_state) = @_;
26                     return( 0, -10, 0 ); # Return accelerations (x,y,rotation)
27               }
28        );
29
30        my $ball_render = sub {
31              my $state = shift;
32
33              $app->draw_rect( undef, 0 );
34              $app->draw_rect( [$state->x, $state->y, 10,10], [255,0,0,255] );
35              $app->update();
36        };
37
38
39        $ball->attach( $app, $ball_render, @params );
40
41        $app->run();
42
43        $ball->detach(); #can be called at anytime (for example when ball 'dies')
44

DESCRIPTION

METHODS

47   set_acceleration
48       Allows you to set the acceleration callback for defining the
49       interface's behaviour in terms of x,y and rotation.
50
51         $interface->set_acceleration (
52             sub {
53                my ($time, $current_state) = @_;
54
55                return ( $accel_x, $accel_y, $torque );
56             }
57         );
58
59       These accelerations are arbitrary and can be set to any frame of
60       reference.  Your render callback will handle how to interpret it.
61
62       The callback will receive the time and the current state as a
63       "SDLx::Controller::State" element.
64
65   attach
66       Attaches the interface to a controller with a render callback
67
68         $interface->attach( $controller, $render, @params );
69
70       Where $render is a callback that receives the interpolated
71       "SDLx::Controller::State".
72
73         my $render = sub {
74               my ($state, @params) = @_;
75               # draw the current $state.
76         };
77
78       The @params are any extra parameters you would like to pass to the
79       $render callback.
80
81   current
82         my $current_state = $interface->current();
83
84       Returns the current state of the interface as a
85       "SDLx::Controller::State".
86
87   previous
88         my $previous_state = $interface->previous();
89
90       Returns the previous state of the interface as a
91       "SDLx::Controller::State".
92
93   detach
94         $interface->detach();
95
96       If $interface has been "attach()"'ed to any controller it will be
97       detached now.
98

OTHER METHODS

100       Don't use these unless you really really want to.
101
102   acceleration
103       Call the acceleration callback once.
104
105   interpolate
106       Interpolate the current state
107
108   evaluate
109       Evaluate the new current and previous state.
110
111   update
112       Update the states by integrating with time.
113

AUTHORS

115       See "AUTHORS" in SDL.
116
117
118
119perl v5.34.0                      2021-07-22    SDLx::Controller::Interface(3)
Impressum