X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=sdlgit%2FSDL-Site.git;a=blobdiff_plain;f=pages%2FSDLx-Controller.html-inc;fp=pages%2FSDLx-Controller.html-inc;h=f01db697c5155cafc0d1eb36f751f610325f1f88;hp=7cf82d55e1aef4cf7860e02adc71272f4acd3b33;hb=fcf60e89673f759573b518df17a379d1a9436b4c;hpb=e785862422f3e827a242fc244bd57b23443887ce diff --git a/pages/SDLx-Controller.html-inc b/pages/SDLx-Controller.html-inc index 7cf82d5..f01db69 100644 --- a/pages/SDLx-Controller.html-inc +++ b/pages/SDLx-Controller.html-inc @@ -13,6 +13,7 @@
min_t
at 1 / 60 ensures that the controller can update the screen at a maximum of 60 times per second.
A "V-Sync" such as this is necessary to prevent video "tear", which occurs when the app is updating faster than the monitor can display.
Setting it to 0, as seen above, will let the app run as fast as it possibly can.
+delay
specifies a loop delay in millisecs to place on the controller loop. NOTE: Picking a good delay based on the needs can help reduce CPU load and pressure.
event
is a SDL::Event object that events going to the event callbacks are polled in to. It defaults to SDL::Event->new()
.
All parameters are optional.
Returns the new object.
@@ -174,6 +176,37 @@ Otherwise, time will accumulate while the application is paused, and many movemeNote 2: a pause will be potentially dangerous to the run
cycle (even if you implement your own) unless called by an event
callback.
Returns 1 if the app is paused, undef otherwise.
+This is only useful when used within code that will be run by pause
:
sub pause { + # press P to toggle pause + + my ($e, $app) = @_; + if($e->type == SDL_QUIT) { + $app->stop; + # quit handling is here so that the app + # can be stopped while paused + } + elsif($e->type == SDL_KEYDOWN) { + if($e->key_sym == SDLK_P) { + # We're paused, so end pause + return 1 if $app->paused; + + # We're not paused, so pause + $app->pause(\&pause); + } + } + return 0; + } + + + + ++ +
Register a callback to handle events. You can add as many subs as you need.