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], h_align => 'right', spacing => 10, mouse => 1, font => 'mygame/data/menu_font.ttf', font_size => 20, font_color => [255, 0, 0], # RGB (in this case, 'red') select_color => [0, 255, 0], active_color => [0, 0, 255], 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. Defaults to [ 0, 0 ].
Sets the preferred menu text alignment. Default is 'center', which will center menu items to their largest entry. Other possible values are 'left' and 'right'.
Sets the line spacing between menu items. Default value is 20. Setting this to 0 will place one item right below the other.
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 selected (clicked) item
RGB value for the font color of the active (hovered) item
File name of the sound to play when the selected item changes
Indicates that menu items can be clicked using a mouse. By default, mouse input is active.
Creates menu items, setting up callbacks for each item.
Breno G. de Oliveira,
<garu at cpan.org>
<kthakore at cpan.org>