From: kthakore
Andy Bakun <sdlperl@thwartedefforts.org>
Benedikt Meurer <bmeurer@fwdn.de>
-Blaise Roth (Blaizer) <blaiseroth@gmail.com>
+Blaise Roth (Blaizer) <blaizer@cpan.org>
Breno G. de Oliveira (garu)
Brian Cassidy (bricas)
chromatic <chromatic@wgz.org>
diff --git a/pages/SDLx-App.html-inc b/pages/SDLx-App.html-inc index a8127cf..df87986 100644 --- a/pages/SDLx-App.html-inc +++ b/pages/SDLx-App.html-inc @@ -106,6 +106,8 @@ Screen depth. Defaults to 16. Shortcut: 'd'. Any flags you want to pass to SDL::Video upon initialization. Defaults to SDL_ANYFORMAT. Flags should be or'ed together if you're passing more than one (flags => FOO|BAR). Shortcut: 'f'.use SDLx::Controller; +use SDLx::Controller; - # create our controller object - my $app = SDLx::Controller->new; - - # register some callbacks - $app->add_event_handler( \&on_event ); - $app->add_move_handler( \&on_move ); - $app->add_show_handler( \&on_show ); - - # run our game loop - $app->run; + # create our controller object + my $app = SDLx::Controller->new; + # we could also do: + my $app = SDLx::App->new; + # because App is also a controller + # register some callbacks + $app->add_event_handler( \&on_event ); + $app->add_move_handler( \&on_move ); + $app->add_show_handler( \&on_show ); + # run our game loop + $app->run;
The core of a SDL application/game is the main loop, where you handle events +
The core of an SDL application/game is the main loop, where you handle events and display your elements on the screen until something signals the end of the program. This usually goes in the form of:
while (1) { @@ -109,10 +110,10 @@ It is only when you change thedt
without changing all the things i If you lower thedt
, everything will move faster than it did with it set higher, and vice-versa. This is useful to add slo-mo and fast-forward features to the game, all you would have to do is change thedt
.-
min_t
specifies the minimum time, in seconds, that has to accumulate before any move or show handlers are called, and defaults to 1 / 60. -Having themin_t
to 1 / 60 ensures that the controller can update the screen at a maximum of 60 times per second. +Having themin_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 in the example, will let the app run as fast as it possibly can.+Setting it to 0, as seen above, will let the app run as fast as it possibly can. +
event
is a SDL::Event object that events going to the event callbacks are polled in to. Defaults toSDL::Event->new()
.
event
is a SDL::Event object that events going to the event callbacks are polled in to. It defaults toSDL::Event->new()
.All parameters are optional.
Returns the new object.
@@ -142,17 +143,22 @@ Note that the second argument every callback recieves is theSDLx::Control
Takes 1 argument which is a callback. The application waits for the next event with
+If the callback returns a false value,wait_event
. When one is recieved, it is passed to the callback as the first argument, along with theSDLx::Controller
object as the second argument. If the callback then returns a true value,pause
will return. -If the callback returns a false value,pause
will indefinitely wait for more events, repeating the process, until the callback returns true.pause
will repeat the process.This can be used to easily implement a pause when the app loses focus:
-sub focus { - my ($e, $controller) = @_; - if($e->type == SDL_ACTIVEEVENT) { +sub window { + 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_ACTIVEEVENT) { if($e->active_state & SDL_APPINPUTFOCUS) { if($e->active_gain) { return 1; } else { - $controller->pause(\&focus); + $app->pause(\&window); # recursive, but only once since the window # can't lose focus again without gaining is first } @@ -178,10 +184,10 @@ The second is theSDLx::Controller
object.sub stop { my ($event, $app) = @_; if($event->type == SDL_QUIT) { - $controller->stop; + $app->stop; } } - $controller->add_event_handler(\&stop); + $app->add_event_handler(\&stop);@@ -195,7 +201,7 @@ and once more for any remaining time less thandt
. The first argument passed to the callbacks is the portion of the step, which will be 1 for a full step, and less than 1 for a partial step. Movement values should be multiplied by this value. The full steps correspond to the amount ofdt
passed between calls, and the partial step corresponds to the call with the remaining time less thandt
. -The argument can be 0 if no time has passed since the last cycle. Set amin_t
if you need to protect against this. +The argument can be 0 if no time has passed since the last cycle. If you need to protect against this, set amin_t
, or put areturn unless $_[0]
at the start of every move handler.The second argument passed to the callbacks is the
SDLx::Controller
object. The third is the total amount of time passed since the call ofrun
.You should use these handlers to update your in-game objects, check collisions, etc. @@ -214,7 +220,7 @@ so you can check and/or update it as necessary.
Register a callback to render objects. You can add as many subs as you need. Returns the order queue number of the added callback. All registered callbacks will be triggered in order, once per run of the
-run
loop.The first argument passed is the number of ticks since the previous call. +
The first argument passed is the time, in seconds, since the previous call. The second is the
SDLx::Controller
object.sub show_ball { my ($delta, $app) = @_; diff --git a/pages/documentation.html-inc b/pages/documentation.html-inc index 317ade7..8a9e770 100644 --- a/pages/documentation.html-inc +++ b/pages/documentation.html-inc @@ -1,2 +1,2 @@-+Documentation (latest development branch)
Core SDL - Simple DirectMedia Layer for Perl SDL::Credits - Authors and contributors of the SDL Perl project SDL::Deprecated - Log of Deprecated items per release SDL::Time - An SDL Perl extension for managing timers
Audio SDL::Audio - SDL Bindings for Audio
Structure SDL::AudioCVT - Audio Conversion Structure SDL::AudioSpec - SDL Bindings for structure SDL::AudioSpec
CDROM SDL::CDROM - SDL Bindings for the CDROM device
Structure SDL::CD - SDL Bindings for structure SDL_CD SDL::CDTrack - SDL Bindings for structure SDL_CDTrack
Events SDL::Events - Bindings to the Events Category in SDL API
Structure SDL::Event - General event structure
Joystick SDL::Joystick - SDL Bindings for the Joystick device
Mouse SDL::Mouse - SDL Bindings for the Mouse device
Structure SDL::Cursor - Mouse cursor structure
Structure SDL::Version - SDL Bindings for structure SDL_Version
Video SDL::Video - Bindings to the video category in SDL API
Structure SDL::Color - Format independent color description SDL::Overlay - YUV Video overlay SDL::Palette - Color palette for 8-bit pixel formats SDL::PixelFormat - Stores surface format information SDL::Rect - Defines a rectangular area SDL::Surface - Graphic surface structure SDL::VideoInfo - Video Target Information
Cookbook SDL::Cookbook SDL::Cookbook::OpenGL - Using SDL with OpenGL SDL::Cookbook::PDL
Extension SDLx::App - a SDL perl extension SDLx::Layer - Storage object for surface and position information SDLx::LayerManager - Extension for managing layers in a 2D world SDLx::Rect - SDL extension for storing and manipulating rectangular coordinates SDLx::SFont - Extension making fonts out of images and printing them SDLx::Sound SDLx::Sprite - interact with images quick and easily in SDL SDLx::Sprite::Animated - create animated SDL sprites easily! SDLx::Surface - Graphic surface matrix extension
Controller SDLx::Controller - Handles the loops for events, movement and rendering SDLx::Controller::Interface - Interface Physics and Rendering with the Controller with callbacks SDLx::Controller::State - the state of a SDLx::Controller::Interface
GFX SDL::GFX::Framerate - framerate calculating functions SDL::GFX::Primitives - basic drawing functions
Structure SDL::GFX::FPSManager - data structure used by SDL::GFX::Framerate
Image SDL::Image - Bindings for the SDL_Image library
Mixer SDL::Mixer - Sound and music functions SDL::Mixer::Channels - SDL::Mixer channel functions and bindings SDL::Mixer::Effects - sound effect functions SDL::Mixer::Groups - Audio channel group functions SDL::Mixer::Music - functions for music SDL::Mixer::Samples - functions for loading sound samples
Structure SDL::Mixer::MixChunk - SDL Bindings for structure SDL_MixChunk SDL::Mixer::MixMusic - SDL Bindings for structure SDL_MixMusic
Pango SDL::Pango - Text rendering engine
Structure SDL::Pango::Context - Context object for SDL::Pango
TODO SDL::MPEG - a SDL perl extension SDL::SMPEG - a SDL perl extension
MultiThread SDL::MultiThread - Bindings to the MultiThread category in SDL API
Structure SDL::RWOps - SDL Bindings to SDL_RWOPs
GFX SDL::GFX::BlitFunc - blitting functions SDL::GFX::ImageFilter - image filtering functions SDL::GFX::Rotozoom - rotation and zooming functions for surfaces
TTF SDL::TTF - True Type Font functions (libfreetype)
Structure SDL::TTF::Font - Font object type for SDL_ttf
Tutorials SDL::Tutorial - introduction to Perl SDL SDL::Tutorial::Animation SDL::Tutorial::LunarLander - a small tutorial on Perl SDL Documentation (latest development branch)
Core SDL - Simple DirectMedia Layer for Perl SDL::Credits - Authors and contributors of the SDL Perl project SDL::Deprecated - Log of Deprecated items per release SDL::Time - An SDL Perl extension for managing timers
Audio SDL::Audio - SDL Bindings for Audio
Structure SDL::AudioCVT - Audio Conversion Structure SDL::AudioSpec - SDL Bindings for structure SDL::AudioSpec
CDROM SDL::CDROM - SDL Bindings for the CDROM device
Structure SDL::CD - SDL Bindings for structure SDL_CD SDL::CDTrack - SDL Bindings for structure SDL_CDTrack
Events SDL::Events - Bindings to the Events Category in SDL API
Structure SDL::Event - General event structure
Joystick SDL::Joystick - SDL Bindings for the Joystick device
Mouse SDL::Mouse - SDL Bindings for the Mouse device
Structure SDL::Cursor - Mouse cursor structure
Structure SDL::Version - SDL Bindings for structure SDL_Version
Video SDL::Video - Bindings to the video category in SDL API
Structure SDL::Color - Format independent color description SDL::Overlay - YUV Video overlay SDL::Palette - Color palette for 8-bit pixel formats SDL::PixelFormat - Stores surface format information SDL::Rect - Defines a rectangular area SDL::Surface - Graphic surface structure SDL::VideoInfo - Video Target Information
Cookbook SDL::Cookbook SDL::Cookbook::OpenGL - Using SDL with OpenGL SDL::Cookbook::PDL
Extension SDLx::App - a SDL perl extension SDLx::Layer - Storage object for surface and position information SDLx::LayerManager - Extension for managing layers in a 2D world SDLx::Rect - SDL extension for storing and manipulating rectangular coordinates SDLx::SFont - Extension making fonts out of images and printing them SDLx::Sound SDLx::Sprite - interact with images quick and easily in SDL SDLx::Sprite::Animated - create animated SDL sprites easily! SDLx::Surface - Graphic surface matrix extension
Controller SDLx::Controller - Handles the loops for events, movement and rendering SDLx::Controller::Interface - Interface Physics and Rendering with the Controller with callbacks SDLx::Controller::State - the state of a SDLx::Controller::Interface
GFX SDL::GFX::Framerate - framerate calculating functions SDL::GFX::Primitives - basic drawing functions
Structure SDL::GFX::FPSManager - data structure used by SDL::GFX::Framerate
Image SDL::Image - Bindings for the SDL_Image library
Mixer SDL::Mixer - Sound and music functions SDL::Mixer::Channels - SDL::Mixer channel functions and bindings SDL::Mixer::Effects - sound effect functions SDL::Mixer::Groups - Audio channel group functions SDL::Mixer::Music - functions for music SDL::Mixer::Samples - functions for loading sound samples
Structure SDL::Mixer::MixChunk - SDL Bindings for structure SDL_MixChunk SDL::Mixer::MixMusic - SDL Bindings for structure SDL_MixMusic
Pango SDL::Pango - Text rendering engine
Structure SDL::Pango::Context - Context object for SDL::Pango
TODO SDL::MPEG - a SDL perl extension SDL::SMPEG - a SDL perl extension
MultiThread SDL::MultiThread - Bindings to the MultiThread category in SDL API
Structure SDL::RWOps - SDL Bindings to SDL_RWOPs
GFX SDL::GFX::BlitFunc - blitting functions SDL::GFX::ImageFilter - image filtering functions SDL::GFX::Rotozoom - rotation and zooming functions for surfaces
TTF SDL::TTF - True Type Font functions (libfreetype)
Structure SDL::TTF::Font - Font object type for SDL_ttf
Tutorials SDL::Tutorial - introduction to Perl SDL SDL::Tutorial::Animation SDL::Tutorial::LunarLander - a small tutorial on Perl SDL