Jeffrey T. Palmer > SDLx-Widget-0.072 > SDLx::Widget::Menu

Download:
SDLx-Widget-0.072.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.072   Source  

NAME ^

SDLx::Widget::Menu - create menus for your SDL apps easily

SYNOPSIS ^

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

DESCRIPTION ^

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!

WARNING! VOLATILE CODE AHEAD ^

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 :)

METHODS ^

new

new( %options )

Creates a new SDLx::Widget::Menu object. No option is mandatory. Available options are:

items( 'Item 1' => \&sub1, 'Item 2' => \&sub2, ... )

event_hook( $event )

render( $surface )

Creates menu items, setting up callbacks for each item.

BUGS AND LIMITATIONS ^

AUTHORS ^

Breno G. de Oliveira, <garu at cpan.org>

Kartik thakore <kthakore at cpan.org>

SEE ALSO ^

SDL, SDLx::App, SDLx::Controller

syntax highlighting: