Core Module (last update 10/03/02)
Description:
This module houses the core routines as well as several non game specific functions and global variables. Notice all core functions are prefixed with Gl_. The functions that are called automatically are detailed here for development reasons only. They have no application other than to initialize the library. The use of this module is mandatory.
UPDATE:
A modification to the main loop was made by Brent
Silby 2002. This modification replaced the setInterval with setTimeout to
cycle the loop. The reason for this change was to bring about more consistent
speed when used with Windows98 machines.
To use:
This module must be the first linked into your script by adding this line to the <HEAD> section of your document:
<script language="Javascript" src="gamelib_core.js"></script>
List of functions for core module
Gl_calibrate()
Gl_cookie()
Gl_getBrowser()
Gl_get_cookies()
Gl_get_window_height()
Gl_get_window_scrollX()
Gl_get_window_scrollY()
Gl_get_window_width()
Gl_hook(fnc)
Gl_layer()
Gl_makedegs()
Gl_preloader(img)
Gl_scrollWindow()
Gl_scrollbars()
Gl_setTimerSpeed()
Gl_start()
Gl_stop()
Gl_unhook(fnc)
List of Global properties for core module
Gl_cos
Gl_failure
Gl_loadwait
Gl_preimage
Gl_sin
Gl_ticker=0
Gl_totalpreimages
Gl_version
Descriptions of functions
Function | Parameters | Description |
---|---|---|
Gl_calibrate | String, Numeric | This function should be used before Gl_start is called. Its purpose is to make your game/animation run at X frames per second, no matter what browser, or CPU the script is running on! The parameters passed are the function to call when the calibration is complete, and the frames per second at which you wish the script to run. |
Gl_cookie | String | Constructor for a cookie. Various methods and properties. Usage explained in cookie docs |
Gl_getbrowser | (none) | Constructor for the Gl_browser object. Called automatically. Checks for compatible browsers on startup, if Gl_browser.panic is true then the visitor is using an unsupported browser. There are various other properties, used internally. |
Gl_get_cookies | (none) | Called automatically. Fills GL_cookies array with cookie name/value pairs |
Gl_get_window_height | (none) | Returns the browser window height |
Gl_get_window_scrollX | (none) | Returns the amount window is scrolled in the X axis |
Gl_get_window_scrollY | (none) | Returns the amount window is scrolled in the Y axis |
Gl_get_window_width | (none) | Returns the browser window width |
Gl_hook | String | Hooks a function to the gamelib timer loop. The string passed is the actual name of the function to be hooked. This function is very useful for tying your functions into the gamelib engine, which will keep things in sync and remove the need for other timers which take valuable CPU cycles |
Gl_layer | Numeric, Numeric, Numeric, String | Layer constructor, read the layer docs for further details |
Gl_makedegs | (none) | Called automatically. Fills Gl_sin and Gl_cos arrays at startup |
Gl_preloader | String[...] | Used to preload images. This function can be passed any number of strings specifying image URLs (ie: "images/picture.gif","images/anotherpic.gif"). Fills an array called Gl_preimage. Also updates Gl_totalpreimages with number of images preloaded |
Gl_scrollbars | String | Turns browser scrollbars on or off for page or frame script is in. String is either "on" or "off". * Note: Only works with Internet Explorer. |
Gl_scrollWindow | Numeric, Numeric |
Scrolls the browser window by x,y where x is first argument and y is second.
You cannot scroll past the edges of the document! Be aware that Netscape/Mozilla browsers require scrollbars in the window for scrolling to work. This can be overcome with Mozilla/Netscape 6 by creating a frameset with the game's frame having the scrollbars switched off. Then inside this frame, place an iframe, sized bigger than the outer frame, so its scrollbars cannot be seen. Your script will be inside this iframe. You can then scroll the iframe window using this method, and to a player, it will look just like a normal frame being scrolled - a la IE4/5! The advantage of using this scroll method, rather than moving all the sprites is that it uses the computer's hardware scrolling, and so is very fast and smooth! |
Gl_setTimerSpeed | Numeric |
NOTE: This function is deprecated. Please use Gl_calibrate instead. Set the timer speed. This will affect the speed the gamelib runs at, based on 1/1000ths of a second between screen updates. Default is 50 (20 frames per second), since it seems the optimum speed for the wide range of speed of PCs/Macs out there. Sure, you can run the gamelib at some insane speed on a dual P3 800mhz by setting this to 1, but you'll annoy people with slower machines unless you have simple (for the CPU) animation |
Gl_start | (none) | Starts the gamelib timer loop. Sprites will not operate until this has been called |
Gl_stop | (none) | Stops the gamelib timer loop. All game functions and animation will cease |
Gl_unhook | String | Unhooks a function. Pass it a string containing the name of the function to unhook |
Descriptions of Global properties
Property | Data Type | Read/Write | Description |
---|---|---|---|
Gl_browser | Object | R | Created when core file is loaded. This checks the browser, to see if it will work with gamelib and sets various properties depending on what it finds. The most important property is Gl_browser.panic which is true if the browser cannot run gamelib scripts. You should check for this first in your game/animation to ensure the visitor is not flooded with errors! |
Gl_cos | Numeric Array | R | Holds 360 elements (0-359). Degrees of circle |
Gl_failure | Boolean | R | Set to true if the gamelib cannot operate. Normally this is because the browser is not dynamic |
Gl_loadwait | Object | R |
NOTE The Gl_loadWait property is deprecated. The starting with version 1.998,
gamelib uses an internal queue to manage the loading of multiple layers,
and so this property will now always be null. If NOT null, then a layer is loading external content. Only 1 layer can load from an external file at a time, so check this is null before attempting to load into a layer. If a layer is loading and you attempt to load another, it will simply not load. See the layer docs for more information about layers. |
Gl_preimage | Image array | R | Holds preloaded images. First image that was preloaded at position [0] |
Gl_sin | Numeric Array | R | Holds 360 elements (0-359). Degrees of circle |
Gl_ticker | Numeric | R/W | Increments by 1 for each game timer loop. Use as you wish |
Gl_totalpreimages | Numeric | R | Holds total images preloaded by Gl_preloader() |
Gl_version | Numeric | R | The version number of the gamelib library |