Using the menus in the game

RPG Creator's user can create your own menus. When installing a plugin, you can assign a pre-created menu.

The advantage is that the user can customize a menu or system malfunction without your plugin

How does it work ?

Your game has a preset plugin : plugins/MenuGenerated. It takes care of launching menus with actions (pressing a key, etc..) or at a specific point in the game (loading map, GameOver, etc.).

Previously, a Menu_Generated object is loaded during a game loading. The data correspond to the fields in the menu tab of the editor.

For Display of your extension, you can get a menu according to its identifier :

Menu_Generated.get("my_menu");

The identifier is returned in the configuration menu :

The recovered data is of this form :

{ 
    _elements: Object
    block: "neither"
    display: "call"
    id: "4"
    menu_id: "my_menu"
    name: "Dialog"
}
  • _elements : List of elements in the menu
  • block :
    • all : map pause
    • player : Only blocks the movement of the player
    • neither : Nothing is blocked
  • display : When the menu is displayed
    • init : When loading the game
    • load_map : Loading map
    • after_map : After loading the map
    • gameover : On GameOver screen
    • key_action : In support of the action key (Enter or Space)
    • key_cancel : In support of the cancellation (Esc)
  • id : Id menu in RPG Creator
  • menu_id : Id declared by the developer menu
  • name : Menu name given by the user

Scene

Above, we collected data from the menu. This does not allow us to do many manipulations above. A menu is actually a scene from the engine CanvasEngine. To retrieve the scene :

var scene = RPGJS.Scene.get("my_menu");

You can then use the API de CanvasEngine to manipulate the scenes.

Note that it is possible to recover the data in this way :

var scene = RPGJS.Scene.get("my_menu"),
    data = scene.data;

Elements

_elements object is the list of elements. But maybe, you want to get a particular element to manipulation.

Get Data

Element also has an identifier. You can specify in the Menu > Elements Setting > General> ID`

Note that there is magic identifiers. RPG Creator uses for some features. They are easily recognized because the identifier begins and ends with two underscores (__)

Example : __text__

This identifier allows us to recover data :

 Menu_Generated.get("my_menu", "my_element");

Manipulate Element

To get an element, you must recover the scene :

var scene = RPGJS.Scene.get("my_menu");

Then use the getElement method with its identifier

var el = scene.getElement("my_element");

The element is an Element object of CanvasEngine. [Use API] (http://canvasengine.net/doc/?p=core.element) to manipulation. Here is an example :

var scene = RPGJS.Scene.get("my_menu"),
    el = scene.getElement("my_element");

el.scaleTo(1.5);
el.on("click", function(e) {
    console.log("click");
});