Games::Console - provide a 2D quake style in-game console
use Games::Console; my $console = Games::Console->new( font => $font_object, background_color => [ 1,1,0], background_alpha => 0.4, text_color => [ 1,1,1 ], text_alpha => 1, speed => 50, # in percent per second height => 50, # fully opened, in percent of screen width => 100, # fully opened, in percent of screen backbuffer_size => 100, # keep so many messages prompt => ' >', cursor => '_', ); $console->screen_width($width); $console->screen_height($height); $console->toggle($current_time); $console->message('Hello there!'); $console->input('a');
Exports nothing on default.
This package provides you with a quake-style console for your games. The console gathers messages and let's you scroll trough them. It also can display a command line.
This package is just a base class setting up everything, but doesn't actually render anything.
See Games::Console::SDL and Games::Console::OpenGL for subclasses that implement the actual rendering to the screen via SDL and OpenGL, respectively.
my $console = Games::Console->new( $args );
Create a new console. Typically, you have only one.
$args is a hash ref containing the following keys:
$args
logfile where to log messages loglevel the log level (e.g. what to log) text_color color of output text as array ref [r,g,b] text_alpha blend font over background for semitransparent background_color color of background as array ref [r,g,b] background_alpha blend console background over screen background
$console->message($message);
Append a message to the console's buffer.
$console->render ( $current_time );
If the console is currently visible, render it.
$console->add_input('a');
Add the text to the current input line (e.g. what is displayed after the prompt). See also input().
$current_input = $console->input(); $console->input('foo');
Get or set the contents of the current input line (e.g. what is displayed after the prompt). See also input().
Example usage after user pressed enter:
$console->message( $console->input() ); $console->input('');
$console->backspace();
Erases the last charcter from the current input buffer, unless the buffer is empty. Returns the current input buffer after the operation.
$rgb = $console->text_color(); # [$r,$g, $b ] $console->color(1,0.1,0.8); # set RGB
Sets the color of the text output.
$rgb = $console->background_color(); # [$r,$g, $b ] $console->background_color(1,0.1,0.8); # set RGB
Sets the color of the background output. See also background_alpha().
$a = $console->text_alpha(); # $a $console->alpha(0.8); # set A $console->alpha(undef); # set's it to 1.0 (seems an OpenGL # specific set because # glColor($r,$g,$b) also sets $a == 1
Sets the alpha value of the rendered text output.
$a = $console->background_alpha(); # $a $console->background_alpha(0.8); # set A
Sets the alpha value of the background (e.g. make it semi-transparent or opaque).
$s = $console->speed(); # in percent $console->color(20); # set new speed (means 5 seconds time)
Gets/sets the opening/closing speed in percent per second, e.g. 25 means 100/25 = 4 seconds time.
$s = $console->cursor(); # get cursor string $console->cursor('_'); # set new cursor
Get/sets the string used as cursor.
$s = $console->prompt(); # get prompt string $console->prompt('_'); # set new prompt string
Get/sets the string used as prompt.
$s = $console->backbuffer_size(); # so many lines $console->backbuffer_size(20); # keep 20
Sets the number of lines in the backbuffer, e.g. how many of the last message lines are kept by the console.
$console->close();
Starts closing the console. See open() and toggle().
$console->open();
Starts opening the console. See close() and toggle().
$console->toggle($current_time);
Toggles the console on or off. See open() and close().
$console->visible(); $console->visible(1);
Makes the console immidiately visible or invisible, unlike open(), close() or toggle(), which gradually move the console in or out.
$console->scroll(-1); $console->scroll(1); $console->scroll(+2);
Scroll the console'soutput by so many lines up or down (to access the backbuffer via SHIFT+CURSOR_UP, for instance). See also offset().
my $offset = $console->offset();
Return the current offset. See scroll().
my $msgs = $console->messages();
Return number of message-lines in backbuffer.
$console->clear();
Erase all message-lines in the backbuffer, e.g. clear it.
None yet.
(c) 2003,2006 Tels <http://bloodgate.com/>
Games::3D, SDL:App::FPS, and SDL::OpenGL.
To install Games::Console, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Games::Console
CPAN shell
perl -MCPAN -e shell install Games::Console
For more information on module installation, please visit the detailed CPAN module installation guide.