Interface Module (last update 03/06/01)

Description:

The module adds objects and methods for communicating information to the player/user and accepting input via gui elements. It's based around the idea of "interface" objects, which are containers holding different input/output elements. Think of an interface as a kind of pinboard, to which you pin other elements such as menus, buttons, labels etc. The interface itself is by default invisible, only the elements it contains are seen (you can change this using the setBgColor method.) The elements you add to an interface can only exist within the interface. So if you create a menu, you will not be able to use it until you add it to an interface.

To use:

The code can be linked in to your script by adding this line to the <HEAD> section of your document:

<script language="Javascript" src="gamelib_interface.js"></script>

You then instantiate an interface by adding the following to your script:

myInterface=new In_Interface(200,200,'../gamelib');

The arguments are width, height and finally the path to the gamelib directory (the one containing all the gamelib_*.js files) The purpose of the final argument there is to help the interface find the image files needed to create certain elements. There should be no slash after the path to the directory. Ok, say you now want to add a numeric display to the interface, at position 50,50 (the position is RELATIVE to the interface's position) with 6 digits, using font face 1:

myDisplay=new In_NumericDisplay(50,50,6,1);
myInterface.add(myDisplay);

As you can see, you create the element first, then add it to the interface. This is the case for all elements. You can keep adding elements to an interface, or you can create multiple interfaces and add some elements to each - handy for multi-screen GUIs! The interface itself can be shown, hidden, and moved in the x, y and z axis. It does not interact with sprites or layers, nor does it respond to the keyboard - however, it can be made draggable!

List of elements that can be placed inside an interface

Button
Image
Label
Cascading Menu
Numeric Display

List of methods for interface module

add
hide
makeDraggable
makeUndraggable
moveTo
setBackground
setBgColor
setZ
show

List of properties for interface module

bgColor
element
visible
x
y
z

Descriptions of methods for interface

MethodParametersDescription
addObject Adds an element to this interface. The element must be an interface element, otherwise nothing will happen. Please note that you cannot use, or even see an element until it has been added to an interface.
hide(none) Hides the elements contained by the interface
makeDraggable(none) Makes the interface draggable. When dragged, all the elements the interface contains will move along with it.
makeUndraggable(none) Stops the interface from being draggable.
moveToNumeric, Numeric Moves the interface to position x,y. This means all the elements contained by this interface will also be moved as an elements position is relative to the position of the interface that contains it.
setBackgroundURL Sets a background image in the interface itself. By default, interfaces are invisible, this gives them a presence on the page. The image will be tiled if it's not as wide or high as the interface.
setBgColorColor Sets the background color of the interface itself. By default, interfaces are invisible, this gives them a presence on the page.
setZNumeric Sets the Z index of the interface. Layers, sprites and interfaces all have a Z index; objects with a higher Z index pass over objects with lower Z indexes. Interfaces differ from other objects in that if an interface is made draggable and it is subsequently dragged, its Z index will be 1 higher than the current highest Z index in all other interfaces on the page. If there are no other interfaces, then the Z index won't be changed.
show(none) Shows the elements contained by the interface

Descriptions of properties for interface

PropertyData TypeRead/WriteDescription
bgColorColorR The current background color of the interface. Normally this will be an empty string, as interfaces have no color by default. Set the color using the setBgColor method.
elementArrayR This is an array of all the elements an interface contains. It is filled as the add method is used, so the first element you add (eg, and numeric display or menu or whatever) will be at index 0, the next at index 1, etc etc. This is useful as you can access the element by using this array, instead of having to create global variables for all elements in an interface.
visibleBooleanR If true, the interface and its elements are visible. * Note the interface itself will not be visible if it has no background color set (the default.) This is set by the show and hide methods.
xNumericR The x position of the interface. Set using the moveTo method.
yNumericR The y position of the interface. Set using the moveTo method.
zNumericR The z position of the interface. Set using the setZ method.