The Console utility

The Console is a command line console that you can implement into your ActionScript projects to make calling commands, methods, and debugging faster. It enables live edit.

Working on commercial games has shown us how useful this utility can be when used on larger projects, these consoles are very common in game engine projects. There is a video tutorial.

Getting started with the console

By default, the console is already instantiated in the Citrus Engine and is enabled. To activate it, uses the TAB key. You will show a black rectangle which is a TextField input. You can easily change the default key:

console.openKey = Keyboard.ALTERNATE;

When you release a game, you should prevent the console to be used. In your Main class write:

console.enabled = false;

To validate a command press the key ENTER

Two commands are already set up in the Console class:

  • get, to trace an object property.
  • set, to live edit an object property.

After opening the console write:

get hero y
set hero y 15

The first one will trace in your IDE console the y hero position. The second one will move your hero to the y 15 value position.

Important: the hero refers to an object registred with the name “hero”, that's the first parameter of a CitrusObject.

Register your own command

The power of the Console class utility is you can easily create your own command to fit your needs. Let's create a command which will pause and unpause our game. In your Main class write:

console.addCommand("pause", pauseGame);
private function pauseGame():void {
	playing = !playing;

To activate this command, you just have to write “pause” into the console. The first argument refers to the console command name, the second to the function called.

Using the LevelManager class, it's powerful to be able to go quickly to the level you want to test. This is the snippet:

console.addCommand("goto", goto);
private function goto(level:uint):void {

Writing “goto 5” will change your game state to the level 5 if it exists! Note that you don't need to mention the paramaters when you register a command.

  citrus/console.txt · Last modified: 2013/01/29 19:14 by aymeric
Powered by DokuWiki