package SDLx::FPS; use strict; use warnings; use SDL::GFX::Framerate; use SDL::GFX::FPSManager; use Carp; our @ISA = qw(SDL::GFX::FPSManager); sub new { my ( $class, %args ) = @_; for ( grep { $_ ne 'fps' } keys %args ) { Carp::cluck("Unrecognized constructor hash key: $_"); } my $fps = $class->SDL::GFX::FPSManager::new( 0, 0, 0, 0 ); SDL::GFX::Framerate::init( $fps ); $fps->set( $args{fps} ) if defined $args{fps}; $fps; } sub set { SDL::GFX::Framerate::set( @_[ 0, 1 ] ); } sub get { SDL::GFX::Framerate::get( $_[0] ); } sub delay { SDL::GFX::Framerate::delay( $_[0] ); } 1; __END__ =head1 NAME SDLx::FPS - a more convenient way to set a framerate =head1 SYNOPSIS use SDLx::FPS; my $fps = SDLx::FPS->new(fps => 60); while(1) { # Main game loop # Do game related stuff $fps->delay; } =head1 DESCRIPTION SDLx::FPS simplifies the task of giving your game a framerate. Basically, it combines the methods of C and C into a single module. Use it to delay the main loop to keep it at a specified framerate. =head1 METHODS =head2 new my $fps = SDLx::FPS->new( fps => 30 ); No arguments are required, if no C is specified, the default FPS is 30. =head2 set $fps->set($new_framerate); Same as C. Set the new desired framerate. =head2 get Same as C. Get the currently set framerate. =head2 delay Same as C. Generate a delay to accommodate currently set framerate. Call once in the graphics/rendering loop. If the computer cannot keep up with the rate (i.e. drawing too slow), the delay is 0 and the delay interpolation is reset. =head2 framecount Return the C. =head2 rateticks Return the C. =head2 lastticks Return the C. =head2 rate Return the C. =head1 AUTHORS See L. =head1 SEE ALSO L<< SDL::GFX::Framerate >>, L<< SDL::GFX::FPSManager >>