The Game Object Class

G.Gob - Description

The name Gob is a contraction of 'Game object'.

Gobs are the items and widgets in your game, things like players, enemies, scenery, layers, viewports, waypoints, panels, buttons, and scoreboards.

They have built-in methods for managing their position and display properties, and they are easy to build, change and automate. Gobs can also have their own AI and custom state.

Structurally, Gobs have a precise internal representation of their shape and position that is used for calculations. They also have a separate internal representation of their UI properties. These UI properties are used for displaying the Gob's 'tag' on the screen. (A tag is a Gob's UI component).

Gobs and tags are explained in detail in the tutorial.

Note: For clarity, this section often uses the 'G.Gob.' prefix when referring to Gob variables and methods. Inside game code, however, the prefix will always be a reference to the Gob instance, eg, 'this.', 'G.O.ship.', etc.

Variables

G.Gob.on (type: boolean)

G.Gob.on is a boolean flag denoting that the Gob is visible and available to interact with other Gobs.

The Gob/Gob and Gob/Mouse collision and intersection functions look at this flag, and will not register an intersection/collision if the Gob is off.

It is also recommended that you write your G.Gob.AI() functions to return immediately if the Gob is off, resulting in a more complete, predictable on/off behaviour.

G.Gob.on is set inside G.Gob.turnOn() and G.Gob.turnOff().

See those functions for more details.

G.Gob.id (type: string)

G.Gob.id is the globally unique ID of the Gob, and can be any legal JavaScript object member name.

Gobs are most commonly accessed using the global Gob set, G.O; eg, G.O.helpMenu.draw();

This variable is set upon Gob creation and should be descriptive; eg, 'viewport', 'alien5', 'bgLevel1', etc.

G.Gob.P (type: object)

G.Gob.P is a reference to the parent Gob of this Gob. The default parent is G, but can be any other Gob. Note that P is not an ID, but an actual object.

This variable is set upon Gob creation and determines a few things.

First, the parent Gob's tag will, by default, be the parent 'container' tag of this Gob's tag. The reason for this is covered in the tutorial.

Second, the parent Gob's (x,y) position will be the origin of this Gob's coordinate system. This means that Gobs with a common parent will share a common frame of reference. This can make positioning a set of related gobs really simple, such as when positioning the elements of a scoreboard. This topic is covered in more depth in the tutorial.

Changing the value of G.Gob.P after the Gob has been created is not recommended, as several other items will also need to be changed. These include the DOM parent of all child Tags and the old and new parent Gobs' CO objects.

G.Gob.B (type: object)

G.Gob.B is a reference to the current Block object, and is set manually.

This is a convenience variable, and can be used for quick access to a Gob's current parent Block.

G.Gob.CO (type: object)

G.Gob.CO is the set of all child Gobs of the Gob. Gobs are added to this set automatically when they are created.

This set is useful for performing batch operations on all child Gobs.

G.Gob.S (type: object)

G.Gob.S is an object for storing Gob-specific state, like start positions, default colors, etc.

GMP doesn't do any housekeeping with G.Gob.S, so you can safely put whatever you want in it.

State variables are often set directly, eg. this.S.startPos=12; and can also be set in a batch using this.setState().

To reset G.Gob.S, simply assign a new object to it (empty or otherwise), eg, this.S={startPos:4}; or this.S={};

To delete a member variable from G.Gob.S, use the delete keyword, eg, delete G.O.alien5.S.trajectory;

Not all Gobs need their own custom internal state. For instance, scenery and viewport Gobs don't generally have any, but NPCs and other dynamic Gobs often will.

G.Gob.x (type: float)

G.Gob.x is the x-coordinate of the Gob, and is relative to the top left corner of its parent Gob, G.Gob.P.x.

This value is important for positioning and intersection/collision management.

G.Gob.x corresponds to a pixel value, eg, 5 == 5px. G.Gob.draw() rounds this value when drawing the Gob's tag.

G.Gob.y (type: float)

G.Gob.y is the y-coordinate of the Gob, and is relative to the top left corner of its parent Gob, G.Gob.P.y.

This value is important for positioning and intersection/collision management.

G.Gob.y corresponds to a pixel value, eg, 5 == 5px. G.Gob.draw() rounds this value when drawing the Gob's tag.

G.Gob.z (type: int)

G.Gob.z is the z-coordinate of the Gob, and is relative to the z-coordinate its parent Gob, G.Gob.P.z.

G.Gob.draw() uses this value directly when drawing the Gob's tag. Unlike x and y, this value is a whole number.

G.Gob.w (type: float)

G.Gob.w is the width of the Gob.

It is used for intersection/collision management.

G.Gob.w corresponds to a pixel value, eg, 5 == 5px. G.Gob.draw() doesn't use this value.

G.Gob.h (type: float)

G.Gob.h is the height of the Gob.

It is used for intersection/collision management.

G.Gob.h corresponds to a pixel value, eg, 5 == 5px. G.Gob.draw() doesn't use this value.

G.Gob.lx (type: float)

G.Gob.lx is the last x-coordinate of the Gob, and is set automatically by G.Gob.setXY().

This value is used by G.Gob.fixIntersection() to fix an intersection between two Gobs.

G.Gob.lx corresponds to a pixel value, eg, 5 == 5px.

See that function for more details.

G.Gob.ly (type: float)

G.Gob.ly is the last y-coordinate of the Gob, and is set automatically by G.Gob.setXY().

This value is used by G.Gob.fixIntersection() to fix an intersection between two Gobs.

G.Gob.ly corresponds to a pixel value, eg, 5 == 5px.

See that function for more details.

G.Gob.nx (type: float)

G.Gob.nx is the next desired x-coordinate of the Gob, and is set automatically by G.Gob.setXY().

This value is used and modified automatically by G.Gob.incrementXY() and G.Gob.fixIntersection().

G.Gob.nx corresponds to a pixel value, eg, 5 == 5px.

See those functions for more details.

G.Gob.ny (type: float)

G.Gob.ny is the next desired y-coordinate of the Gob, and is set automatically by G.Gob.setXY().

This value is used and modified automatically by G.Gob.incrementXY() and G.Gob.fixIntersection().

G.Gob.ny corresponds to a pixel value, eg, 5 == 5px.

See those functions for more details.

G.Gob.tag (type: DOM object)

G.Gob.tag is the UI component of a Gob. It is an HTML tag, and can have any of the properties of HTML, including classes, styles, and its own internal HTML.

The default tag is a <DIV>, assigned automatically upon Gob creation, but almost any other HTML tag can be used.

G.Gob.tag is only visible when the Gob is 'on' (G.Gob.on==1). Its display properties are flushed to the screen using G.Gob.draw().

G.Gob.tag.id (type: string)

G.Gob.tag.id is the globally unique ID of the tag, and is the same value as G.Gob.id, and is set automatically upon Gob creation.

This variable is useful for referencing tags in external game CSS files.

G.Gob.tag.className (type: string)

G.Gob.tag.className is a DOM tag attribute, corresponding to 'class=""'. It is used internally by the Gob functions that manage classes on tags.

You don't need to touch this. Use G.Gob.setVar(), G.Gob.addClass(), G.Gob.removeClass() or G.Gob.swapClass() to manage a tag's classes.

G.Gob.tag.style.position (type: string)

G.Gob.tag.style.position is a DOM tag style attribute. It is automatically set to the value 'absolute', so that the tag is positioned correctly on the screen.

Changing can really give you grief. There are exceptions, which are covered the tutorial.

G.Gob.tag.style.overflow (type: string)

G.Gob.tag.style.overflow is a DOM tag style attribute. It is automatically set to the value 'hidden', so that the tag is doesn't display scrollbars on the screen.

If your tag needs scrollbars, change this value with G.Gob.setStyle().

G.Gob.tag.style.display (type: string)

G.Gob.tag.style.display is a DOM tag style attribute. It is automatically set to the value 'none', so that the tag isn't visible on the screen.

This value is set inside G.Gob.turnOn() and G.Gob.turnOff(). It shouldn't be set manually.

G.Gob.nextStyle (type: object)

G.Gob.nextStyle is a queue for changes to be flushed to the tag's style attribute on the next call to G.Gob.draw().

Style attribute values are added to this object using G.Gob.setVar() or G.Gob.setStyle(). G.Gob.draw() copies the values G.Gob.nextStyle to G.Gob.tag.style, and then empties G.Gob.nextStyle.

Changes can be cancelled before they are applied by deleting the offending attribute, eg, delete G.Gob.nextStyle.color;

Note that new style properties can be set at any time, and then flushed to the screen when appropriate using G.Gob.draw().

G.Gob.nextSrc (type: string)

G.Gob.nextSrc is a queue for new tag content. If the tag is an <IMG>, then this value is the URL of a new image (the 'src' attribute on an IMG tag). If the tag is anything else, then the G.Gob.nextSrc value will be assigned as the inner HTML of the tag.

This variable is set using G.Gob.setVar() or G.Gob.setSrc(), and is flushed to the tag with G.Gob.draw(). G.Gob.draw() empties G.Gob.nextSrc after applying it to the tag.

Changes can be cancelled before they are applied by setting G.Gob.nextSrc to null.

Note that this value can be set anywhere, and then flushed to the screen when appropriate using G.Gob.draw().

G.Gob.nextVal (type: string)

G.Gob.nextVal is a queue for changes to a tag's value attribute. G.Gob.nextVal is similar to G.Gob.nextSrc, but is for <INPUT> tags.

This variable is set using G.Gob.setVal() or G.Gob.setSrc(), and is flushed to the tag with G.Gob.draw(). G.Gob.draw() empties G.Gob.nextVal after applying it to the tag.

Changes can be cancelled before they are applied by setting G.Gob.nextVal to null.

Note that this value can be set anywhere, and then flushed to the screen when appropriate using G.Gob.draw().

G.Gob.classes (type: array)

G.Gob.classes is the set of all classes assigned to G.Gob.tag. It is an internal variable used by the Gob functions that manage classes on tags.

You don't need to touch this. Use G.Gob.setVar(), G.Gob.addClass(), G.Gob.removeClass() or G.Gob.swapClass() to manage a tag's classes.

G.Gob.tx (type: float)

G.Gob.tx is the x-offset of the tag from G.Gob.x, and it defaults to 0.

G.Gob.tx corresponds to a pixel value, eg, 5 == 5px. G.Gob.draw() rounds this value when drawing the Gob's tag.

G.Gob.ty (type: float)

G.Gob.ty is the y-offset of the tag from G.Gob.y, and it defaults to 0.

G.Gob.ty corresponds to a pixel value, eg, 5 == 5px. G.Gob.draw() rounds this value when drawing the Gob's tag.

G.Gob.tw (type: float)

G.Gob.tw is the width of the tag, and it defaults to the width of the Gob, G.Gob.w.

This variable is set to the value of G.Gob.w automatically whenever G.Gob.w is set with G.Gob.setVar(). It can also be set to a custom value (different from G.Gob.w) by setting it explicitly, eg, G.Gob.setVar({tw:555}); Both w and tw can be set in the same call to setVar(), and will be set correctly.

G.Gob.tw corresponds to a pixel value, eg, 5 == 5px. G.Gob.draw() rounds this value when drawing the Gob's tag.

G.Gob.th (type: float)

G.Gob.th is the height of the tag, and it defaults to the height of the Gob, G.Gob.h.

This variable is set to the value of G.Gob.h automatically whenever G.Gob.h is set with G.Gob.setVar(). It can also be set to a custom value (different from G.Gob.h) by setting it explicitly, eg, G.Gob.setVar({th:555}); Both h and th can be set in the same call to setVar(), and will be set correctly.

G.Gob.th corresponds to a pixel value, eg, 5 == 5px. G.Gob.draw() rounds this value when drawing the Gob's tag.

G.Gob.cw (type: int)

G.Gob.cw is the clip-width of the tag, and it defaults to the width of the Gob, G.Gob.w.

Set this explicitly when the tag is a tiled IMG sprite, otherwise just ignore it.

In a tiled image sprite, G.Gob.cw is the width of each tile (all tiles will have same width), and G.Gob.tw is the the width of the actual image.

This variable is set to the value of G.Gob.w automatically whenever G.Gob.w is set with G.Gob.setVar(). It can also be set to a custom value (different from G.Gob.w) by setting it explicitly, eg, G.Gob.setVar({cw:555}); Both w and cw can be set in the same call to setVar(), and will be set correctly.

G.Gob.cw corresponds to a pixel value, eg, 5 == 5px, and should be set to whole number values.

G.Gob.ch (type: int)

G.Gob.ch is the clip-height of the tag, and it defaults to the height of the Gob, G.Gob.h.

Set this explicitly when the tag is a tiled IMG sprite, otherwise just ignore it.

In a tiled image sprite, G.Gob.ch is the height of each tile (all tiles will have same height), and G.Gob.th is the the height of the actual image.

This variable is set to the value of G.Gob.h automatically whenever G.Gob.h is set with G.Gob.setVar(). It can also be set to a custom value (different from G.Gob.h) by setting it explicitly, eg, G.Gob.setVar({ch:555}); Both h and ch can be set in the same call to setVar(), and will be set correctly.

G.Gob.ch corresponds to a pixel value, eg, 5 == 5px, and should be set to whole number values.

G.Gob.cx (type: int)

G.Gob.cx is the x-coordinate of a tile in an image sprite tile grid. It defaults to 0.

Set this explicitly when the tag is a tiled IMG sprite, otherwise just ignore it.

In GMP, the tiles in an IMG sprite are arranged in a grid, and each tile is referenced by an (x,y) coordinate on that grid. The top-left tile has coordinate (0,0). The x-coordinate increases to the right, and the y-coordinate increases downward on the grid.

This variable is set with G.Gob.setVar(), and should be set to whole number values.

G.Gob.cy (type: int)

G.Gob.cy is the y-coordinate of a tile in an image sprite tile grid. It defaults to 0.

Set this explicitly when the tag is a tiled IMG sprite, otherwise just ignore it.

In GMP, the tiles in an IMG sprite are arranged in a grid, and each tile is referenced by an (x,y) coordinate on that grid. The top-left tile has coordinate (0,0). The x-coordinate increases to the right, and the y-coordinate increases downward on the grid.

This variable is set with G.Gob.setVar(), and should be set to whole number values.

G.Gob.docx (type: int)

G.Gob.docx is the absolute x-position of the Gob's tag in the HTML document.

For all practical purposes, G.Gob.docx is relative to the left side of the HTML document.

G.Gob.docx is important for testing if a Gob's tag contains the mouse pointer. It must be recalculated if the window resizes, and so is always recalculated just before use. This is done automatically for G.Gob.tagContainsMouse(), G.Gob.tagContainsMouseDown(), and G.Gob.tagContainsMouseClick().

It can be calculated manually with G.Gob.calcAbsoluteTagPosition().

G.Gob.docx corresponds to a pixel value, eg, 5 == 5px.

G.Gob.docy (type: int)

G.Gob.docy is the absolute y-position of the Gob's tag in the HTML document.

For all practical purposes, G.Gob.docy is relative to the top of the HTML document.

G.Gob.docy is important for testing if a Gob's tag contains the mouse pointer. It must be recalculated if the window resizes, and so is always recalculated just before use. This is done automatically for G.Gob.tagContainsMouse(), G.Gob.tagContainsMouseDown(), and G.Gob.tagContainsMouseClick().

It can be calculated manually with G.Gob.calcAbsoluteTagPosition().

G.Gob.docy corresponds to a pixel value, eg, 5 == 5px.

G.Gob.drawX (type: boolean)

G.Gob.drawX is a boolean flag. It must be set to true for G.Gob.draw() to update the Gob tag's x-position on screen.

It is set to true automatically when G.Gob.setVar() is passed a new x or tx value, or when G.Gob.setXY() is passed a new x value. It is also set to true when G.Gob.draw(force) is passed any value (ie, force == true).

G.Gob.drawY (type: boolean)

G.Gob.drawY is a boolean flag. It must be set to true for G.Gob.draw() to update the Gob tag's y-position on screen.

It is set to true automatically when G.Gob.setVar() is passed a new y or ty value, or when G.Gob.setXY() is passed a new y value. It is also set to true when G.Gob.draw(force) is passed any value (ie, force == true).

G.Gob.drawZ (type: boolean)

G.Gob.drawZ is a boolean flag. It must be set to true for G.Gob.draw() to update the Gob tag's z-index on screen.

It is set to true automatically when G.Gob.setVar() is passed a new z value.

G.Gob.drawW (type: boolean)

G.Gob.drawW is a boolean flag. It must be set to true for G.Gob.draw() to update the Gob tag's width on screen.

It is set to true automatically when G.Gob.setVar() is passed a new w, or tw value.

G.Gob.drawH (type: boolean)

G.Gob.drawH is a boolean flag. It must be set to true for G.Gob.draw() to update the Gob tag's height on screen.

It is set to true automatically when G.Gob.setVar() is passed a new h, or th value.

G.Gob.drawClip (type: boolean)

G.Gob.drawClip is a boolean flag. It must be set to true for G.Gob.draw() to change the Gob tag's IMG sprite tile on screen.

It is set to true automatically when G.Gob.setVar() is passed a new cw, ch, cx, or cy value.

G.Gob.drawClass (type: boolean)

G.Gob.drawClass is a boolean flag. It must be set to true for G.Gob.draw() to update the Gob tag's class attribute on screen.

It is set to true automatically when G.Gob.setVar() is passed a new addClass or removeClass value, or when classes are updated with any of G.Gob.addClass(), G.Gob.removeClass() or G.Gob.swapClass().

Methods

Note: many of the following methods return an object instead of returning nothing. The returned object is often the parent object (i.e., the Gob). Doing this allows for method chaining, which can lead to compact code. The tutorial has examples that use chaining.

G.Gob.AI() (returns this)

G.Gob.AI() is the 'brain' function of a Gob.

This is a stub function that should be overwritten if you want your Gob to manage its own logic.

Most Gobs in a game will not need AI, but it can be useful for NPCs and other 'smart' objects.

See the tutorial for more details about using this function.

G.Gob.turnOn() (returns this)

G.Gob.turnOn() makes a Gob's tag visible, and flushes all its display properties to the screen. It also sets G.Gob.on to true, a flag wich denotes that the Gob is available to interact with other Gobs.

See G.Gob.on for more details.

G.Gob.turnOff() (returns this)

G.Gob.turnOff() makes a Gob's tag invisible and sets G.Gob.on to false.

See G.Gob.turnOn() and G.Gob.on for more details.

G.Gob.draw(force) (returns this)

G.Gob.draw(force) flushes changes to a tag's properties to the screen. It also performs all necessary conversion from the internal represention of these properties to their DOM equivalents.

The tag properties that G.Gob.draw(force) flushes are:

  • position and dimension
  • class and style attributes
  • content (IMG src, innerHTML, or INPUT value)
Some properties are flushed if a new value is queued, while others must be flagged for update. All these properties, as well as the draw flags, are described above in the G.Gob variables section.

The 'force' argument is a boolean that will set all draw flags to true, causing all flagged properties to be flushed to screen. The 'force' argument doesn't affect non-flagged properties.

Note:

This is the most expensive function in the engine with respect to resources. Draw operations are very computationally intensive for the web browser, so this function should be scheduled carefully.

As well, G.Gob.draw(force) ignores the G.Gob.on flag, so a Gob tag's properties can be flushed, even though it is not visible on screen. This can be useful for behind-the-scenes updating, but care should be taken to avoid drawing 'off' Gobs unnecessarily.

G.Gob.setVar(O) (returns this)

G.Gob.setVar(O) adds the members of object 'O' to the G.Gob object. In general, if a member of O exists in G.Gob, then it over-writes the existing value, otherwise it just adds it.

There are several exceptions to this, as G.Gob.setVar(O) also performs a few housekeeping tasks, like synchronizing similar variables and setting internal draw flags.

The parameters with special processing are defined below. If a parameter isn't listed, then it will simply be added or updated with no extra processing.

"x"

If G.Gob.setVar(O) is passed 'x', eg, G.Gob.setVar({x:55.55}); then G.Gob.x will be updated with the value of x.

Also, G.Gob.drawX will be set to true, so that G.Gob.draw() will redraw the x-position of G.Gob.tag.

"y"

If G.Gob.setVar(O) is passed 'y', eg, G.Gob.setVar({y:55.55}); then G.Gob.y will be updated with the value of y.

Also, G.Gob.drawY will be set to true, so that G.Gob.draw() will redraw the y-position of G.Gob.tag.

"z"

If G.Gob.setVar(O) is passed 'z', eg, G.Gob.setVar({z:1000}); then G.Gob.z will be updated with the value of z.

Also, G.Gob.drawZ will be set to true, so that G.Gob.draw() will redraw the z-index of G.Gob.tag.

"w"

If G.Gob.setVar(O) is passed 'w', eg, G.Gob.setVar({w:200.5}); then G.Gob.w, G.Gob.tw and G.Gob.cw will be updated with the value of w.

If G.Gob.setVar(O) is also passed 'tw', eg, G.Gob.setVar({w:200.5, tw:35}); then G.Gob.tw of tw instead of w.

If G.Gob.setVar(O) is also passed 'cw', eg, G.Gob.setVar({w:200.5, cw:35}); then G.Gob.cw of cw instead of w.

In all these cases, G.Gob.drawW will be set to true, so that G.Gob.draw() will redraw the width of G.Gob.tag.

"h"

If G.Gob.setVar(O) is passed 'h', eg, G.Gob.setVar({h:200.5}); then G.Gob.h, G.Gob.th and G.Gob.ch will be updated with the value of h.

If G.Gob.setVar(O) is also passed 'th', eg, G.Gob.setVar({h:200.5, th:35}); then G.Gob.th of th instead of h.

If G.Gob.setVar(O) is also passed 'ch', eg, G.Gob.setVar({h:200.5, ch:35}); then G.Gob.ch of ch instead of h.

In all these cases, G.Gob.drawH will be set to true, so that G.Gob.draw() will redraw the height of G.Gob.tag.

"tx"

If G.Gob.setVar(O) is passed 'tx', eg, G.Gob.setVar({tx:55}); then G.Gob.tx will be updated with the value of tx.

Also, G.Gob.drawX will be set to true, so that G.Gob.draw() will redraw the x-position of G.Gob.tag.

"ty"

If G.Gob.setVar(O) is passed 'ty', eg, G.Gob.setVar({ty:55}); then G.Gob.ty will be updated with the value of ty.

Also, G.Gob.drawY will be set to true, so that G.Gob.draw() will redraw the y-position of G.Gob.tag.

"tw"

If G.Gob.setVar(O) is passed 'tw', eg, G.Gob.setVar({tw:35}); then G.Gob.tw will be updated with the value of tw.

Also, G.Gob.drawW will be set to true, so that G.Gob.draw() will redraw the y-position of G.Gob.tag.

"th"

If G.Gob.setVar(O) is passed 'th', eg, G.Gob.setVar({th:35}); then G.Gob.th will be updated with the value of th.

Also, G.Gob.drawH will be set to true, so that G.Gob.draw() will redraw the height of G.Gob.tag.

"cx"

If G.Gob.setVar(O) is passed 'cx', eg, G.Gob.setVar({cx:3}); then G.Gob.cx will be updated with the value of cx.

Also, G.Gob.drawClip will be set to true, so that G.Gob.draw() will redraw the x,y position and clip of G.Gob.tag.

"cy"

If G.Gob.setVar(O) is passed 'cy', eg, G.Gob.setVar({cy:2}); then G.Gob.cy will be updated with the value of cy.

Also, G.Gob.drawClip will be set to true, so that G.Gob.draw() will redraw the x,y position and clip of G.Gob.tag.

"cw"

If G.Gob.setVar(O) is passed 'cw', eg, G.Gob.setVar({cw:35}); then G.Gob.cw will be updated with the value of cw.

Also, G.Gob.drawClip will be set to true, so that G.Gob.draw() will redraw the x,y position and clip of G.Gob.tag.

"ch"

If G.Gob.setVar(O) is passed 'ch', eg, G.Gob.setVar({ch:35}); then G.Gob.ch will be updated with the value of ch.

Also, G.Gob.drawClip will be set to true, so that G.Gob.draw() will redraw the x,y position and clip of G.Gob.tag.

"addClass"

G.Gob.setVar(O) can be accept the 'addClass' parameter in two forms

  • as a string, eg, G.Gob.setVar({addClass:'class1'});
  • as an array, eg, G.Gob.setVar({addClass:['class1','class2','class3]});

All classes passed to G.Gob.setVar(O) with the 'addClass' parameter are added to the G.Gob.classes array. Duplicates are filtered out.

Also, G.Gob.drawClass will be set to true, so that G.Gob.draw() will replace the classes in G.Gob.tag.className with those in G.Gob.classes.

"removeClass"

G.Gob.setVar(O) can be accept the 'removeClass' parameter in two forms

  • as a string, eg, G.Gob.setVar({removeClass:'class1'});
  • as an array, eg, G.Gob.setVar({removeClass:['class1','class2','class3]});

All classes passed to G.Gob.setVar(O) with the 'removeClass' parameter are removed from the G.Gob.classes array.

Also, G.Gob.drawClass will be set to true, so that G.Gob.draw() will replace the classes in G.Gob.tag.className with those in G.Gob.classes.

"nextStyle"

If G.Gob.setVar(O) is passed the 'nextStyle' parameter, all object members of nextStyle will be added to G.Gob.nextStyle.

If a member of nextStyle is already in G.Gob.nextStyle then it over-writes the existing value.

G.Gob.setState(O) (returns this)

G.Gob.setState(O) adds the members of object 'O' to the G.Gob.S object. If a member of O exists in G.Gob.S, then it over-writes the existing value, otherwise it just adds it.

This function returns the parent Gob object.

See G.Gob.S for more details.

G.Gob.resetState(O) (returns this)

G.Gob.resetState(O) is a wrapper around G.Gob.setState(O). It deletes the existing G.Gob.S object before calling G.Gob.setState(O).

G.Gob.setStyle(O) (returns this)

G.Gob.resetStyle(O) is a short-cut to G.Gob.setVar(O).

G.Gob.resetStyle(O) accepts an object as an argument.

These two function calls are equivalent: myGob.setStyle({color:'red', backgroundColor:'blue'}); and myGob.setVar({nextStyle:{color:'red', backgroundColor:'blue'}});

G.Gob.addClass() (returns this)

G.Gob.addClass() is a short-cut to G.Gob.setVar(O).

G.Gob.addClass() can accept a string or an array of strings as an argument.

Notice that this method doesn't name it's parameter(s) in the method definition. This is because it uses the JavaScript built-in arguments parameter to retrieve whatever you pass in.

These two function calls are equivalent: myGob.addClass('red'); and myGob.setVar({addClass:'red'});

G.Gob.removeClass() (returns this)

G.Gob.removeClass() is a short-cut to G.Gob.setVar(O).

G.Gob.removeClass() can accept a string or an array of strings as an argument.

Notice that this method doesn't name it's parameter(s) in the method definition. This is because it uses the JavaScript built-in arguments parameter to retrieve whatever you pass in.

These two function calls are equivalent: myGob.removeClass('red'); and myGob.setVar({removeClass:'red'});

G.Gob.swapClass(a, b) (returns this)

G.Gob.swapClass(a, b) is a short-cut to G.Gob.setVar(O), used to remove class a and add class b.

G.Gob.swapClass(a, b) accepts two strings for arguments.

These two pieces of code are equivalent: myGob.swapClass('red','blue'); and myGob.setVar({removeClass:'red'}).setVar(addClass:'blue');

G.Gob.setVal(str) (returns this)

G.Gob.setVal(str) is a short-cut to G.Gob.setVar(O).

G.Gob.setVar(str) accepts a string for its argument.

These two pieces of code are equivalent: myGob.setVal('type your response here'); and myGob.setVar({nextVal:'type your response here'});

G.Gob.setSrc(str) (returns this)

G.Gob.setSrc(str) is a short-cut to G.Gob.setVar(O).

G.Gob.setSrc(str) accepts a string for its argument.

These two pieces of code are equivalent: myGob.setSrc('/path/to/alienCruiser.gif'); and myGob.setSrc({nextVal:'/path/to/alienCruiser.gif'});

G.Gob.calcAbsoluteTagPosition() (returns this)

G.Gob.calcAbsoluteTagPosition() calculates the absolute position of G.Gob.tag, and stores it in G.Gob.docx and G.Gob.docy.

This is a helper function used by G.Gob.tagContainsXY(), but can also be used at any time by game code.

G.Gob.tagContainsXY(x, y, skip) (returns boolean)

G.Gob.tagContainsXY(x,y,skip) calculates if the given (x,y) coordinate falls inside G.Gob.tag. The coordinate (x,y) is relative to the document, and so is useful for mouse coordinates.

The parameter 'skip' is a boolean, and if set to true, G.Gob.tagContainsXY(x y, skip) will not call G.Gob.calcAbsolutePosition(). This can make the function a little faster on older browsers.

The is primarily a helper function used by G.Gob.tagContainsMouse(), G.Gob.tagContainsMouseDown(), and G.Gob.tagContainsMouseClick().

G.Gob.tagContainsMouse() (returns boolean)

G.Gob.tagContainsMouse() returns true if G.Gob.on is true and the mouse is hovering over the Gob's tag.

Note:

The event capture/execution model in the GMP game engine is very different from the model used by a web browser.

See the tutorial for details about using the mouse input manager and creating mouse events.

G.Gob.tagContainsMouseDown() (returns boolean)

G.Gob.tagContainsMouseDown() returns true if G.Gob.on is true and a mouse button is pressed inside the Gob's tag.

Note:

The event capture/execution model in the GMP game engine is very different from the model used by a web browser.

See the tutorial for details about using the mouse input manager and creating mouse events.

G.Gob.tagContainsMouseClick() (returns boolean)

G.Gob.tagContainsMouseClick() returns true if G.Gob.on is true and a mouse button was pressed and released inside the Gob's tag.

Note:

The event capture/execution model in the GMP game engine is very different from the model used by a web browser.

See the tutorial for details about using the mouse input manager and creating mouse events.

G.Gob.checkIntersection(gob) (returns boolean)

G.Gob.checkIntersection(gob) returns true if this Gob intersects the supplied Gob, false otherwise.

There are some important constraints on this function:

  • Both Gobs must have the same parent Gob (same frame of reference). See the tutorial for more about frames of reference.
  • The supplied Gob must be on, eg 'gob.on==1'.
  • It tests the intersection of the Gobs, not their tags. This is important to note because tags are often larger than their Gob.
This function is called as a part of the logic to make Gobs 'hard' or 'solid'. See the tutorial for details about making Gobs solid.

If there are no 'hard' or 'solid' Gobs in your game, then this function can be used to detect collisions (nearly) as effectively as G.Gob.checkCollision(gob).

G.Gob.checkCollision(gob) (returns boolean)

G.Gob.checkCollision(gob) returns true if this Gob is within 0.6px, or overlaps, the supplied Gob (or overlaps it). It returns false otherwise.

There are some important constraints on this function:

  • Both Gobs must have the same parent Gob (same frame of reference). See the tutorial for more about frames of reference.
  • The supplied Gob must be on, eg 'gob.on==1'.
  • It tests the intersection of the Gobs, not their tags. This is important to note because tags are often larger than their Gob.
This function is similar to G.Gob.checkIntersection(gob), except that it will also detect adjacent Gobs that are 'just touching'. This is important if there are 'hard' or 'solid' Gobs in your game, since the closest they will get is 'just touching'.

See the tutorial for details about managing Gob collisions.

G.Gob.setXY(O) (returns this)

G.Gob.setXY(O) is an alternate function to G.Gob.setVar(O). It is used to set G.Gob.x, G.Gob.y, G.Gob.nx and G.Gob.ny on Gobs that will undergo intersection and collision detection.

This function synchronizes (G.Gob.x, G.Gob.y), (G.Gob.lx,G.Gob.ly) and (G.Gob.nx, G.Gob.ny) so that G.Gob.incrementXY() and G.Gob.fixIntersection(gob) behave as expected.

Use this function if you are using G.Gob.incrementXY() or G.Gob.fixIntersection(gob) on a Gob.

See the tutorial for details about using this function for collision management.

G.Gob.incrementXY() (returns this)

G.Gob.incrementXY() moves the Gob the maximum allowable increment in preparation for collision detection.

Technically, it increments (G.Gob.x, G.Gob.y) in the direction of (G.Gob.nx, G.Gob.ny) by a maximum distance of G.Gob.w or G.Gob.h, whichever is smaller.

This function requires that G.Gob.lx, G.Gob.ly, G.Gob.nx and G.Gob.ny are set correctly.

See the tutorial for details about using this function for collision management.

G.Gob.fixIntersection(gob) (returns this)

G.Gob.fixIntersection(gob) 'rewinds' the position of the Gob if it is intersecting the supplied Gob.

It stops 'rewinding' when the Gobs are no longer intersecting. They will be within 0.5px of each other.

Technically, it increments (G.Gob.x, G.Gob.y) in the direction of (G.Gob.lx, G.Gob.ly) in increments of 0.5px until the two Gobs no longer intersect.

This function requires that G.Gob.lx, G.Gob.ly, G.Gob.nx and G.Gob.ny are set correctly.

See the tutorial for details about using this function for collision management.

Previous: G.Block Next: G.Mouse