You will find here a description of all the functions and objects offerd by gameQuery.
gameQuery allows you to declare animations. Animations are made of one image with a succession of frames just like in a css sprite. An animation in itself doesn’t exist until it’s associated with a sprite. Those are the attributes an animation can have:
example:
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.
This function defines the div to be used to display the game. All the objects to be added to the DOM by gameQuery will be added to this element or on of its child. If more than one element results from the expression only the first will be used.
Options may contain:
If the key tracker is enabled you can check at anymoment the state of every key by looking into the array $.gQ.keyTracker, the indexes of this arrays are keycodes. If the mouse tracker is enabled you can check the state of the mouse at anytime by looking into the object $.gQ.mouseTracker where x and y contain the position of the mouse and 1, 2 and 3 a boolean value where true means that the first, second or thrid button is pressed
example:
Called without any parameters the playground function returns the current playground.
This function will prepare the game to be started by pre-loading the resources and will start the main loop. If a function is given as a parameter it will be called once everything is loaded.
example:
This function pauses the game. Animations are stopped, all elements (sprites, groups and tile-maps) are hidden and callbacks WON’T be called anymore.
This function 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 gameQuery’s defined callbacks since they won’t be executed during a paused game, in a event handler for example.
This function registers a function to be called at a regular interval. The rate is the number of milliseconds between two successive calls to the function given as argument.
If the function passed as an argument returns a integer it will change the interval to which to function is called. If the function returns the boolean ‘true’ then the callback will not be called anymore.
This function adds a sprite to the current selected element. This element is expected to be the playground, a group or another sprite. Any sprite created this way will automatically animate itself. The sprite will stay hidden as long as the start() function hasn’t been called.
Options may include:
example:
This function behaves almost in the same way as the addSprite one but it creates a transparent sprite.
Options may include:
example:
This function creates a tilemap using the animations from animationList and arranging them according to the tileDescription. animationList can be an array of animation or a multi-animation. tileDescription can be an array of integer where the value of each point is the index of the animation in the animationList (or the multi-animaiton index) or a function taking as parameter a x and y index and returning the index of the animation for this point. Tiles created by this method are marked by the “tileType_x” class where x is the animation index (this may be useful for colision). Remark: this doesn’t work if the tilemap is transformed (rotation or scalling)
Options may include:
The buffer option 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)
example:
This function imports a JSON file generated by Tiled. All the created tilemaps will be directly under the currently selected element. Their name will be made of the provided prefix followed by a number starting at 0.
Only layer of type “tilelayer” are supported for now. Only one single tileset per layer is supported.
After the call to this function the second argument will hold two new arrays:
This function allow to change the animation of the element on which it’s called. This element is expected to be a sprite. Callback is a function to call at the end of each animation cycle. It’s an optional parameter that will only be used if the animation is of type $.gQ.CALLBACK. Called whitout any parameter this function remove the animation from the selected sprite.
If the currently assigned animation is a mutli-animations the animation
argument can be the index of the animation you want to choose amongst one of the multi-animations.
Stops the animation of the selected element at the current frame. If the animation has one frame or is already paused this has not effect.
Resume the animation of the selected element if it was paused. If the animation has not been paused this has no effect.
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().
Will clear all sprites, groups and tile-maps but animations and sounds too. If you passe true as an argument all callbacks will be removed too. It is recommended to call this function when the game is paused with pauseGame().
Sets the coordinates of the sprite/group/tilemap. If relative is set to true then the arguments are increments to the current position. If called without arguments, the function will return an object {x: x-coordinate, y: y-coordinate, z: z-coordinate}.
Sets the coordinates of the sprite/group/tilemap. If relative is set to true then the arguments are increments to the current position. If called without arguments, the function will return an object {x: x-coordinate, y: y-coordinate, z: z-coordinate}. The z value is present in the return object because it comes at no cost.
Sets the x-coordinates of the sprite/group/tilemap. If relative is set to true then the arguments are increments to the current position. If called without arguments, the function will return the value of the x-coordinate. (The x-coordinate corresponds to the CSS “left” property)
Sets the y-coordinates of the sprite/group/tilemap. If relative is set to true then the arguments are increments to the current position. If called without arguments, the function will return the value of the y-coordinate. (The x-coordinate corresponds to the CSS “top” property)
Sets the z-coordinates of the sprite/group/tilemap. If relative is set to true then the arguments are increments to the current position. If called without arguments, the function will return the value of the z-coordinate. (The x-coordinate corresponds to the CSS “z-index” property)
Sets the width and height of the sprite/group/tilemap. If relative is set to true then the arguments are increments to the current dimensions. If called without arguments, the function will return an object {w: width, h: height}.
Sets the width of the sprite/group/tilemap. If relative is set to true then the arguments are increments to the current dimensions. If called without arguments, the function will return the width.
Sets the height of the sprite/group/tilemap. If relative is set to true then the arguments are increments to the current dimensions. If called without arguments, the function will return the height.
This method returns the list of elements collisioning with the selected one but only those that match with the filter given as parameter. It takes two optional arguments (their order is not important). The filter is a string filtering element used to detect collision, it should contain all the elements the function should search collision into. For example if you look for collision with element of the class ‘foo’ that may be contained in a group you will use the filter ".group,.foo"
.
You may want watch the following video tutorial I did to explain how this all works or read the following discussion on the forum. The override is 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.
example:
This function sets a callback to be called with the current loading progress (in percent) as argument.
This function adds the sound to the current object. If a sound is already associated with this object it will be replaced unless the add argument is set to true. In this case both sounds will be associated with the object.
This function plays the sound or sounds associated with the current object.
This function stops the sound or sounds associated with the current object.
This function pauses the sound or sounds associated with the current object.
This function mutes the sound or sounds associated with the current object or mute all sounds if no obect is selected. If you pass false to the function it unmutes instead of mutes.
This function rotates the selected element(s) clock-wise. The first argument is an angle degree. The second argument is a flag that define if the rotation is relative or not (false by default). If sets to true the first argument is added to the current rotation.
This function change the scale of the selected element(s). The first argument is a ratio: 1.0 = original size, 0.5 = half the original size, 2.0 = twice the original size. The second argument is a flag that define if the scaling is relative or not (false by default). If sets to true the current scaling is multiplied by the provided value (and not added like for the other transformation).