Added new pages and docs
[sdlgit/SDL-Site.git] / pages / SDLx-Controller.html-inc
index 7cf82d5..f01db69 100644 (file)
@@ -13,6 +13,7 @@
 <li><a href="#run">run</a></li>
 <li><a href="#stop">stop</a></li>
 <li><a href="#pause">pause</a></li>
+<li><a href="#paused">paused</a></li>
 <li><a href="#add_event_handler">add_event_handler</a></li>
 <li><a href="#add_move_handler">add_move_handler</a></li>
 <li><a href="#add_show_handler">add_show_handler</a></li>
@@ -113,6 +114,7 @@ This is useful to add slo-mo and fast-forward features to the game, all you woul
 Having the <code>min_t</code> at 1 / 60 ensures that the controller can update the screen at a maximum of 60 times per second.
 A &quot;V-Sync&quot; such as this is necessary to prevent video &quot;tear&quot;, 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.</p>
+<p><code>delay</code> specifies a loop delay in millisecs to place on the controller loop. <strong>NOTE:</strong> Picking a good delay based on the needs can help reduce CPU load and pressure.</p>
 <p><code>event</code> is a SDL::Event object that events going to the event callbacks are polled in to. It defaults to <code>SDL::Event-&gt;new()</code>.</p>
 <p>All parameters are optional.</p>
 <p>Returns the new object.</p>
@@ -174,6 +176,37 @@ Otherwise, time will accumulate while the application is paused, and many moveme
 <p>Note 2: a pause will be potentially dangerous to the <code>run</code> cycle (even if you implement your own) unless called by an <code>event</code> callback.</p>
 
 </div>
+<h2 id="paused">paused</h2>
+<div id="paused_CONTENT">
+<p>Returns 1 if the app is paused, undef otherwise.
+This is only useful when used within code that will be run by <code>pause</code>:</p>
+<pre> sub pause {
+     # press P to toggle pause
+
+     my ($e, $app) = @_;
+     if($e-&gt;type == SDL_QUIT) {
+         $app-&gt;stop;
+         # quit handling is here so that the app
+         # can be stopped while paused
+     }
+     elsif($e-&gt;type == SDL_KEYDOWN) {
+         if($e-&gt;key_sym == SDLK_P) {
+             # We're paused, so end pause
+             return 1 if $app-&gt;paused;
+
+             # We're not paused, so pause
+             $app-&gt;pause(\&amp;pause);
+         }
+     }
+     return 0;
+ }
+
+
+
+
+</pre>
+
+</div>
 <h2 id="add_event_handler">add_event_handler</h2>
 <div id="add_event_handler_CONTENT">
 <p>Register a callback to handle events. You can add as many subs as you need.