SDL-App-FPS
view release on metacpan or search on metacpan
lib/SDL/App/FPS.pm view on Meta::CPAN
SDL_MOUSEMOVED, SDL_MOUSEBUTTONDOWN etc) and then for $kind kind of it,
like SDLK_SPACE. Mouse movement events ignore the $kind parameter.
The created handler is added to the application.
See L<SDL::App::FPS::EventHandler::new()> for details.
One clever and usefull thing is to define the key bindings in the config file
under the section C<[input]> like this:
bind_event_some_name = f
bind_event_some_other = SPACE
bind_event_more = RMB
And then do this:
my $handler = SDL::App::FPS::EventHandler->new(
FPS_EVENT,
'some_name',
$callback
);
This means rebinding the event to a different key needs no change in your code.
=item del_event_handler
Delete an event handler from the application.
=item event_bound_to
$name = $app->event_bound_to('some_event');
Rreturn the name of the key/button the event handler is bound to, usefull
for handlers of type C<FPS_EVENT>. See L<add_event_handler()>.
=item app()
my $sdl_app = $self->app();
Return a pointer to the SDL application object. Usefull for calling it's
methods.
=item option()
print $app->option('max_fps'),"\n"; # get
$app->option('max_fps',40); # set to 40
Get/sets an option defined by the key (name) and an optional value.
=item freeze_time_warp_ramp()
$app->freeze_time_warp_ramp();
Disables any ramping of the time warp that might be in effect.
=item freeze_time()
$app->freeze_time();
Sets the time warp factor to 0, effectively stopping the warped clock. Note
that the real clock still ticks and frames are still drawn, so you can overlay
some menu/animation over a static (froozen in time) background. Of course it
might be more efficient to save the current drawn frame as image and stop
the drawing if the not-changing background altogether.
=item thaw_time()
$app->thaw_time();
Sets the time warp factor back to what it was before L<freeze_time()> was
called. Does nothing when the clock is not frozen.
=item ramp_time_warp
$app->ramp_time_warp($target_factor,$time_to_ramp);
Set a tagret time warp factor and a time it will take to get to this factor.
The time warp (see L<time_warp()>) will then be gradually adjusted to the
target factor. C<$time_to_ramp> is in ms (aka 1000 == one second).
It is sometimes a good idea to read out the current time warp and ramp it to
a specific factor, like so:
$time_warp = $app->time_warp();
$app->ramp_time_warp($time_warp * 2, 1000);
But you need to restrict this somehow, otherwise the clock might be speed up
or slowed down to insanely high or low speeds. So sometimes it is just better
to do this:
sub enable_slow_motion
{
# no matter how fast clock now is, slow it down to a fixed value
$app->ramp_time_warp(0.5, 1000);
}
When ramp_time_warp() is called without arguments, and ramping is in effect,
it returns a list consisting of:
target factor # to where we ramp
time to ramp # how long it takes (ticks)
current time warp # where are currently
start time warp # from where we ramp (factor)
start time warp time # from where we ramp (real time ticks)
When no ramping is in effect, it returns an empty list or undef.
You can disable/stop the time warping by setting a new time warp factor
directly like so:
my $t = $app->time_warp(); $app->time_warp($t);
Or easier:
$app->freeze_time_warp();
=item time_warp
$app->time_warp(2); # fast forward
Get or set the current time warp, e.g. the factor how fast the time passes.
( run in 2.069 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )