GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
pods::SDLx::Controller::Interface(3) User Contributed Perl Documentation pods::SDLx::Controller::Interface(3)

SDLx::Controller::Interface - Interface Physics and Rendering with the Controller with callbacks

Extension, Controller

 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')

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.

The callback will receive the time and the current state as a "SDLx::Controller::State" element.

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.

  my $current_state = $interface->current();

Returns the current state of the interface as a "SDLx::Controller::State".

  my $previous_state = $interface->previous();

Returns the previous state of the interface as a "SDLx::Controller::State".

  $interface->detach();

If $interface has been "attach()"'ed to any controller it will be detached now.

Don't use these unless you really really want to.

Call the acceleration callback once.

Interpolate the current state

Evaluate the new current and previous state.

Update the states by integrating with time.

See "AUTHORS" in SDL.
2022-06-07 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.