API Changes in 0.7

onaluf edited this page Jul 5, 2012 · 1 revision

Here is a list of the new features and API changes of gameQuery 0.7:

gQ alias

There is now an alias to make calls to thing like $.gameQuery.Animation shorter: you can use $.gQ.Animation. This is just an alias and both name will remain valid!

fliph() and flipv()

The behavior of those two functions when called without argument has change. They use to consider a call without argument as meaning 'change the flipping state'. Now a call without argument means 'return the current state'. That way they behave like rotate() and scale().


You can replace old call to $(....).flipv() with $(....).flipv(!$(....).flipv())

collision function override

The collision function allows you to pass an argument that will override the position and size of the selected element.

new API

collsion() now take two optional arguments (their order is not important):

  1. the filter, a string filtering element used to detect collision (like before)
  2. the override, an object containing one or more of the following properties: x and y to override the element position, w and h to override the width and height.

Mouse Tracker

Just like for the keyTracker you can now specify mouseTracker: true in your playground definition and the position as well as the button state of the mouse will be tracked.

new API

Once activated you can look at the $.gameQuery.mouseTracker object to read the mouse state. It has five properties:

  • x the x coordinate where the origin is the top-left angle of the playground
  • y the y coordinate where origin is the top-left angle of the playground
  • 1 the state of the fist button (true = pressed)
  • 2 the state of the second button (true = pressed)
  • 3 the state of the third button (true = pressed)

CSS namespacing

The CSS classes and ids used by gameQuery are now namespaced with gQ_to avoid interferences with classes set by your game or other plug-ins. You can access them through a constant in the gameQuery object so that should they change for some reason you won't have the change the code of your game. Most of the time you will use them only when you write a filter for the collision() function.

new API

  • $.gameQuery.spriteCssClass the CSS class associated with every sprites (replaces sprite)
  • $.gameQuery.groupCssClass the CSS class associated with every groups (replaces group)
  • $.gameQuery.tilemapCssClass the CSS class associated with every tile-maps (replaces tileSet)
  • $.gameQuery.tileCssClass the CSS class associated with every tiles (sort of replaces active)
  • $.gameQuery.tileTypePrefix the prefix of the CSS class used to make the type of each tiles. A tile with the animation number 3 will have the class $.gameQuery.tileTypePrefix + 3 (replaces tileType_)
  • $.gameQuery.tileIdPrefix the prefix of the id for each tiles. A tile a the 4th line and 7th column in the tile-map array will have the id $.gameQuery.tileIdPrefix + 4 + "_" + 7 (replaces tile_)


Rewrite your filters if you used them in any call to collision()

Dynamic tilemaps

In 0.6 all the tiles of the tile-map were added to the DOM (but only visible ones were animated). Now Only the visible tiles and a buffer around them are present in the DOM. When moving the tile-map around makes it necessary the missing tiles are added to the DOM.

new API

The collision() methode now takes a new option: buffer (default value 1). It defines the number of tiles around the visible ones that are created in advance. If you find that moving tiles around is to slow you may want to play with this value . One possible scenario is when you have a player jumping around, if you now that it will move up a little and them down the same amount most of the time you may want to make sure that the buffer is big enough so that the top most point of the jump doesn't forces the tile-map to create new tiles. Keep in mind that the bigger the buffer the slower it is to add new tiles (because the buffer has to be re-created to)

Pause and resume

You can now pause and resume the game.

new API

  • pauseGame() pauses the game: animations are stopped, all elements (sprites, groups and tile-maps) are hidden and callbacks WON'T be called anymore.
  • resumeGame(callback) resumes the game: animations stats again, all elements are made visible again and callbacks start firing again. If any new animations or sound have been added they will be loaded and once done the function callback passed as argument will be called. If a loading callback has been defined at some point it will be called during the loading of the new element. Please note that you have to call this function outside one of gQ's defined callbacks since they won't be executed during a paused game, in a event handler for example.

Clearing the game

You can now delete all the elements (sprites, groups and tile-maps) in one call to .clearScenegraph(). If you want to remove resources and optionally callbacks you can use clearAll().

new API

  • clearScenegraph() will clear all sprites, groups and tile-maps. Please make sure that after a call to this your callbacks don't try to access to them. It is recommended to call this function when the game is paused with pauseGame().
  • clearAll(callbacksToo) will clear all sprites, groups and tile-maps but animations and sounds too. You you passe trueas an argument all callbacks will be removed too. It is recommended to call this function when the game is paused with pauseGame().
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.