SDLx::Widget::Menu - create menus for your SDL apps easily
Create a simple SDL menu for your game/app:
my $menu = SDLx::Widget::Menu->new->items( 'New Game' => \&play, 'Options' => \&settings, 'Quit' => \&quit, );
Or customize it at will:
my $menu = SDLx::Widget::Menu->new( topleft => [100, 120], font => 'game/data/menu_font.ttf', font_size => 20, font_color => [255, 0, 0], # RGB (in this case, 'red') select_color => [0, 255, 0], change_sound => 'game/data/menu_select.ogg', )->items( 'New Game' => \&play, 'Options' => \&settings, 'Quit' => \&quit, );
After that, all you have to do is make sure your menu object's hooks are called at the right time in your game loop:
# in the event loop $menu->event_hook( $event ); # $event is a SDL::Event # in the rendering loop $menu->render( $screen ); # $screen is a SDL::Surface
Main menus are a very common thing in games. They let the player choose between a new game, loading games, setting up controls, among lots of other stuff. This menu widget is meant to aid developers create menus quickly and easily, so they can concentrate in their game's logic rather than on such a repetitive task. Simple menus, easy. Complex menus, possible!
This is a new module and the API is subject to change without notice. If you care, please join the discussion on the #sdl IRC channel in irc.perl.org. All thoughts on further improving the API are welcome.
You have been warned :)
Creates a new SDLx::Widget::Menu object. No option is mandatory. Available options are:
Determines topmost and leftmost positions for the menu.
File name of the font used to render menu text.
Size of the font used to render menu text.
RGB value to set the font color.
RGB value for the font color of the select item
File name of the sound to play when the selected item changes
Creates menu items, setting up callbacks for each item.
Breno G. de Oliveira,
<garu at cpan.org>
<kthakore at cpan.org>