Skip to content

gameQuery.ext Documentation

robbrit edited this page Sep 14, 2010 · 1 revision

QuadTree

A quadtree is a data structure designed for dividing up the world space so that objects in the game world may be accessed based on their location within the world. This is useful for things like collision detection, where in order to detect collisions you only really need to look at objects near one another.
Note that the maximum number of objects within one node is 5 (this can be changed by modifying the code within gameQuery.ext, but is not currently configurable). This is not a problem as the node will just split if a node contains more than that, however if you have at least 5 objects superimposed on the same location the node will enter an infinite loop of splitting.

QuadTree Methods

QuadTree(width, height) – creates a QuadTree object for the world with width width and height height.

add(object, x, y) – adds object to the tree at location (x, y).

get(x, y, width, height) – retrieves all objects in the tree within the rectangle defined by (x, y, width, height).

View

This object creates a scrollable viewport using two HTML elements: one for the viewport, and one within the viewport for use as a background. Typically the viewport will be your playground and the background will be div generated by gameQuery called sceengraph [sic], however you are not restricted to this. The View object only assumes that the background is a child of the viewport.

View Methods

View(viewport, background, options) – creates the viewport using viewport as the viewport and background as the background. Note that these must be jQuery objects!
Possible options include:

  • width/height: the width/height of the background. The View object will resize the background to match these dimensions.
  • imageURL: the image to use for the background. The image will be tiled.

frame(timeStep) – This method does nothing for the View class.

scroll(dx, dy) – Scrolls the background by (dx, dy).

anchor(x, y) – Sets the position of the viewport to be at (x, y) within the background. For example if you call view.anchor(10, 10), the top left corner of the viewport will be set to (10, 10) above the background.

LockedView

The LockedView class is a child of the View class which is designed to follow a specific jQuery element. This is useful for games where the viewport will follow a character (ie. side-scrolling games).

LockedView Methods

LockedView(target, viewport, background, options) – target is the jQuery object that the viewport will follow, the rest of the parameters are passed directly to View().

frame(timeStep) – when this method is called the view will re-adjust to centre itself on the target object. Usually you call this when the target moves.

Other Functions

rectOverlap(x1, y1, w1, h1, x2, y2, w2, h2) – returns true if the two rectangles defined by (x1, y1, w1, h1 ) and (x2, y2, w2, h2 ) are overlapping, false if not.

keyDown(key) – returns true if key is down. This is a tweak to make key checking easier. For example you would go:


if (keyDown("space")) {
  // ... stuff to do when space is down
}

getTimeElapsed() – returns the number of milliseconds elapsed since the last time getTimeElapsed() was called. The first time it is called it will return 0.