Documentation

Make your choice on the side menu in order to navigate through the documentation.

addStateConstant

Add a new state constant to JSGlib. You must call this method BEFORE running your game.
JSGlib addStateConstant ( String constantName )
Parameters
Name of the constant to add.
Returns: JSGlib
The JSGlib object.

ajax

Performs an Ajax request.
JSGlib ajax ( Object options )
Parameters
Options setting the request.
{
'url': URL to call. (required),
'async': Boolean indicating if request must be asynchronous (true) or synchronous (false). Default: true,
'type': 'GET' or 'POST'. Default: 'GET',
'dataType': Type of data to receive from server: 'TEXT', 'XML' or 'JSON'. Default: 'TEXT',
'data': Object containing values to send to the server. Default: {},
'onAjaxAborted': function () { Function called if request is aborted },
'onError': function () { Function called if an errors occurs },
'onSuccess': function () { Function called when the request is successfully finished }
'onComplete': function () { Function called after request is finished, after onError() or onSuccess() }
}
Returns: JSGlib
The JSGlib object.

BACKGROUND

Object containing constants for behavior or background-repeat for layers.
Values
NO_REPEAT
REPEAT
REPEAT_X
REPEAT_Y

Color

A class representing a color.
Color ( Array[Number] color, [ Bool isHSL ] )
Parameters
An array containing the amount of Red, Green and Blue for the new color.
If true, the first parameter will be considered as HSL values and not RGB ones. Default: false.
Color ( String color )
Parameters
An hexadecimal representation of the color (starting with #) or a color name (red, blue etc.).
Color ( JSGlib.Color color )
Parameters
The color to copy.

equals

Check if color is the same than the given one.
Bool equals ( JSGlib.Color color )
Parameters
Color to check.
Returns: Bool
true if colors are equal. false otherwise.

getHexadecimal

Get the hexadecimal representation of the color.
String getHexadecimal ( )
Returns: String
The hexadecimal representation of the color (starting with #).

getHSL

Get the HSL representation of the color.
Object getHSL ( )
Returns: Object
An object containing the properties "hue", "saturation" and "lightness".

getRGB

Get the RGB representation of the color.
Object getRGB ( )
Returns: Object
An object containing the properties "red", "green" and "blue".

NAMES

Object containing constants for several colors names.
Values
ALICEBLUE
ANTIQUEWHITE
AQUA
AQUAMARINE
AZURE
BEIGE
BISQUE
BLACK
BLANCHEDALMOND
BLUE
BLUEVIOLET
BROWN
BURLYWOOD
CADETBLUE
CHARTREUSE
CHOCOLATE
CORAL
CORNFLOWERBLUE
CORNSILK
CRIMSON
CYAN
DARKBLUE
DARKCYAN
DARKGOLDENROD
DARKGRAY
DARKGREEN
DARKGREY
DARKKHAKI
DARKMAGENTA
DARKOLIVEGREEN
DARKORANGE
DARKORCHID
DARKRED
DARKSALMON
DARKSEAGREEN
DARKSLATEBLUE
DARKSLATEGRAY
DARKSLATEGREY
DARKTURQUOISE
DARKVIOLET
DEEPPINK
DEEPSKYBLUE
DIMGRAY
DIMGREY
DODGERBLUE
FIREBRICK
FLORALWHITE
FORESTGREEN
FUCHSIA
GAINSBORO
GHOSTWHITE
GOLD
GOLDENROD
GRAY
GREEN
GREENYELLOW
GREY
HONEYDEW
HOTPINK
INDIANRED
INDIGO
IVORY
KHAKI
LAVENDER
LAVENDERBLUSH
LAWNGREEN
LEMONCHIFFON
LIGHTBLUE
LIGHTCORAL
LIGHTCYAN
LIGHTGOLDENRODYELLOW
LIGHTGRAY
LIGHTGREEN
LIGHTGREY
LIGHTPINK
LIGHTSALMON
LIGHTSEAGREEN
LIGHTSKYBLUE
LIGHTSLATEGRAY
LIGHTSLATEGREY
LIGHTSTEELBLUE
LIGHTYELLOW
LIME
LIMEGREEN
LINEN
MAGENTA
MAROON
MEDIUMAQUAMARINE
MEDIUMBLUE
MEDIUMORCHID
MEDIUMPURPLE
MEDIUMSEAGREEN
MEDIUMSLATEBLUE
MEDIUMSPRINGGREEN
MEDIUMTURQUOISE
MEDIUMVIOLETRED
MIDNIGHTBLUE
MINTCREAM
MISTYROSE
MOCCASIN
NAVAJOWHITE
NAVY
OLDLACE
OLIVE
OLIVEDRAB
ORANGE
ORANGERED
ORCHID
PALEGOLDENROD
PALEGREEN
PALETURQUOISE
PALEVIOLETRED
PAPAYAWHIP
PEACHPUFF
PERU
PINK
PLUM
POWDERBLUE
PURPLE
RED
ROSYBROWN
ROYALBLUE
SADDLEBROWN
SALMON
SANDYBROWN
SEAGREEN
SEASHELL
SIENNA
SILVER
SKYBLUE
SLATEBLUE
SLATEGRAY
SLATEGREY
SNOW
SPRINGGREEN
STEELBLUE
TAN
TEAL
THISTLE
TOMATO
TURQUOISE
VIOLET
WHEAT
WHITE
WHITESMOKE
YELLOW
YELLOWGREEN

setBlue

Change the amount of blue in the color.
JSGlib.Color setBlue ( Number amount, [ Bool isRelative ] )
Parameters
The new amount of blue. [0 - 255]
If true, the first parameter will be added to the current amount of blue instead of replace it. Default: false.
Returns: JSGlib.Color
The calling JSGlib.Color.

setGreen

Change the amount of green in the color.
JSGlib.Color setGreen ( Number amount, [ Bool isRelative ] )
Parameters
The new amount of green. [0 - 255]
If true, the first parameter will be added to the current amount of green instead of replace it. Default: false.
Returns: JSGlib.Color
The calling JSGlib.Color.

setHue

Change the hue of the color.
JSGlib.Color setHue ( Number value, [ Bool isRelative ] )
Parameters
The new value of the hue. [0 - 359]
If true, the first parameter will be added to the current hue instead of replace it. Default: false.
Returns: JSGlib.Color
The calling JSGlib.Color.

setLightness

Change the lightness of the color.
JSGlib.Color setLightness ( Number value, [ Bool isRelative ] )
Parameters
The new value of the lightness. [0 - 100]
If true, the first parameter will be added to the current lightness instead of replace it. Default: false.
Returns: JSGlib.Color
The calling JSGlib.Color.

setRed

Change the amount of red in the color.
JSGlib.Color setRed ( Number amount, [ Bool isRelative ] )
Parameters
The new amount of red. [0 - 255]
If true, the first parameter will be added to the current amount of red instead of replace it. Default: false.
Returns: JSGlib.Color
The calling JSGlib.Color.

setSaturation

Change the saturation of the color.
JSGlib.Color setSaturation ( Number value, [ Bool isRelative ] )
Parameters
The new value of the saturation. [0 - 100]
If true, the first parameter will be added to the current saturation instead of replace it. Default: false.
Returns: JSGlib.Color
The calling JSGlib.Color.

Drawing

An object containing some classes to draw stuffs.

BLENDING_MODES

Object containing constants representing blending modes for filters.
Values
ADDITION
AVERAGE
BURN
DARKEN_ONLY
DIFFERENCES
DIVIDE
DODGE
GRAIN_EXTRACT
GRAIN_MERGE
HARD_LIGHT
LIGHTEN_ONLY
MULTIPLY
NORMAL
OVERLAY
SCREEN
SUBSTRACT

CANVAS_FILTER

HTML canvas object managing filters.

Circle

A class representing a drawing circle.
Circle ( Number radius )
Parameters
Radius of the circle.

draw

Draw the object. This method will be automatically called by JSGlib, you should not call it by yourself!
draw ( CanvasRenderingContext2D ctx )
Parameters
Context to draw.

radius

Number radius ( )
Get the radius of the circle.
Returns: Number
Radius of the circle.
JSGlib.Drawing.Circle radius ( Number radius )
Set the radius of the circle.
Parameters
The new radius.
Returns: JSGlib.Drawing.Circle
The calling Drawing.Circle.

CTX_FILTER

Context 2D of the canvas managing filters.

Filter

A class representing a drawing filter.
Filter ( JSGlib.Drawing.MODE mode )
Parameters
Blending mode of the filter.

draw

Draw the object. This method will be automatically called by JSGlib, you should not call it by yourself!
draw ( CanvasRenderingContext2D ctx )
Parameters
Context to draw.

mode

JSGlib.Drawing.MODE mode ( )
Get the blending mode of the filter.
Returns: JSGlib.Drawing.MODE
The blending mode.
JSGlib.Drawing.Filter mode ( JSGlib.Drawing.MODE sprite )
Set the blending mode of the filter.
Parameters
The new blending mode.
Returns: JSGlib.Drawing.Filter
The calling drawing filter.

Line

A class representing a drawing line.
Line ( JSGlib.Point firstPoint, JSGlib.Point secondPoint )
Parameters
First point of the line.
Second point of the line.

color

JSGlib.Color color ( )
Get the color of the drawing line.
Returns: JSGlib.Color
The color of the drawing line.
JSGlib.Drawing.Line color ( Array[Number] color, [ Bool isHSL ] )
Set the color of the drawing drawing line.
Parameters
An array containing the amount of Red, Green and Blue for the new color.
If true, the first parameter will be considered as HSL values and not RGB ones. Default: false.
Returns: JSGlib.Drawing.Line
The calling Drawing.Line.
JSGlib.Drawing.Line color ( String color )
Set the color of the drawing line.
Parameters
An hexadecimal representation of the color (starting with #) or a color name (red, blue etc.).
Returns: JSGlib.Drawing.Line
The calling Drawing.Line.
JSGlib.Drawing.Line color ( JSGlib.Color color )
Set the color of the drawing line.
Parameters
The color to copy.
Returns: JSGlib.Drawing.Line
The calling Drawing.Line.

draw

Draw the object. This method will be automatically called by JSGlib, you should not call it by yourself!
draw ( CanvasRenderingContext2D ctx )
Parameters
Context to draw.

firstPoint

JSGlib.Point firstPoint ( )
Get the first point of the line.
Returns: JSGlib.Point
The first point of the line.
JSGlib.Drawing.Line firstPoint ( JSGlib.Point firstPoint )
Set the first point of the line.
Parameters
The new point.
Returns: JSGlib.Drawing.Line
The calling Drawing.Line.

secondPoint

JSGlib.Point secondPoint ( )
Get the second point of the line.
Returns: JSGlib.Point
The second point of the line.
JSGlib.Drawing.Line secondPoint ( JSGlib.Point firstPoint )
Set the second point of the line.
Parameters
The new point.
Returns: JSGlib.Drawing.Line
The calling Drawing.Line.

Object

An abstract class representing a drawing object.

borderColor

JSGlib.Color borderColor ( )
Get the border color of the drawing object.
Returns: JSGlib.Color
The border color of the drawing object.
JSGlib.Drawing.Object borderColor ( Array[Number] borderColor, [ Bool isHSL ] )
Set the border color of the drawing object.
Parameters
An array containing the amount of Red, Green and Blue for the new border color.
If true, the first parameter will be considered as HSL values and not RGB ones. Default: false.
Returns: JSGlib.Drawing.Object
The calling Drawing.Object.
JSGlib.Drawing.Object borderColor ( String borderColor )
Set the border color of the drawing object.
Parameters
An hexadecimal representation of the color (starting with #) or a color name (red, blue etc.).
Returns: JSGlib.Drawing.Object
The calling Drawing.Object.
JSGlib.Drawing.Object borderColor ( JSGlib.Color borderColor )
Set the border color of the drawing object.
Parameters
The color to copy.
Returns: JSGlib.Drawing.Object
The calling Drawing.Object.

borderSize

Number borderSize ( )
Get the border size of the drawing object.
Returns: Number
The border size of the drawing object.
JSGlib.Drawing.Object borderSize ( Number borderSize )
Set the border size of the drawing object.
Parameters
The new border size.
Returns: JSGlib.Drawing.Object
The calling Drawing.Object.

color

JSGlib.Color color ( )
Get the color of the drawing object.
Returns: JSGlib.Color
The color of the drawing object.
JSGlib.Drawing.Object color ( Array[Number] color, [ Bool isHSL ] )
Set the color of the drawing object.
Parameters
An array containing the amount of Red, Green and Blue for the new color.
If true, the first parameter will be considered as HSL values and not RGB ones. Default: false.
Returns: JSGlib.Drawing.Object
The calling Drawing.Object.
JSGlib.Drawing.Object color ( String color )
Set the color of the drawing object.
Parameters
An hexadecimal representation of the color (starting with #) or a color name (red, blue etc.).
Returns: JSGlib.Drawing.Object
The calling Drawing.Object.
JSGlib.Drawing.Object color ( JSGlib.Color color )
Set the color of the drawing object.
Parameters
The color to copy.
Returns: JSGlib.Drawing.Object
The calling Drawing.Object.

draw

draw ( )
This method should be overwritted by inherited classes.

opacity

Number opacity ( )
Get the opacity of the drawing object.
Returns: Number
The opacity of the drawing object.
JSGlib.DrawingObject opacity ( Number opacity )
Set the opacity of the drawing object.
Parameters
The new opacity.
Returns: JSGlib.DrawingObject
The calling drawing object.

Rectangle

A class representing a drawing rectangle.
Rectangle ( [ number width ], [ number height ] )
Parameters
Width of drawing rectangle. Default: 1.
Height of drawing rectangle. Default: 1.

draw

Draw the object. This method will be automatically called by JSGlib, you should not call it by yourself!
draw ( CanvasRenderingContext2D ctx )
Parameters
Context to draw.

height

Number height ( )
Get the height of the rectangle.
Returns: Number
The height of the rectangle.
JSGlib.Drawing.Rectangle height ( Number height )
Set the height of the rectangle.
Parameters
The new height.
Returns: JSGlib.Drawing.Rectangle
The calling Drawing.Rectangle.

width

Number width ( )
Get the width of the rectangle.
Returns: Number
The width of the rectangle.
JSGlib.Drawing.Rectangle width ( Number width )
Set the width of the rectangle.
Parameters
The new width.
Returns: JSGlib.Drawing.Rectangle
The calling Drawing.Rectangle.

Shape

A class representing a drawing shape.
Shape ( Array[JSGlib.Point] points )
Parameters
An array of Points composing the shape to draw.

draw

Draw the object. This method will be automatically called by JSGlib, you should not call it by yourself!
draw ( CanvasRenderingContext2D ctx )
Parameters
Context to draw.

points

Array[JSGlib.Point] points ( )
Get the points of the shape.
Returns: Array[JSGlib.Point]
A list of the points of the shape.
JSGlib.Drawing.Shape points ( Array[JSGlib.Point] points )
Set the points of the shape.
Parameters
The new points.
Returns: JSGlib.Drawing.Shape
The calling Drawing.Shape.

Sprite

A class representing a drawing sprite.
Sprite ( JSGlib.Sprite sprite )
Parameters
Sprite to draw.

draw

Draw the object. This method will be automatically called by JSGlib, you should not call it by yourself!
draw ( CanvasRenderingContext2D ctx )
Parameters
Context to draw.

filter

JSGlib.Drawing.Filter filter ( )
Get the filter of the drawing sprite.
Returns: JSGlib.Drawing.Filter
The filter of the drawing sprite.
JSGlib.Drawing.Sprite filter ( JSGlib.Drawing.Filter filter )
Set the filter of the drawing sprite.
Parameters
The new filter.
Returns: JSGlib.Drawing.Sprite
The calling Drawing.Sprite.

sprite

JSGlib.Sprite sprite ( )
Get the sprite of the drawing object.
Returns: JSGlib.Sprite
The sprite to draw.
JSGlib.Drawing.Sprite sprite ( JSGlib.Sprite sprite )
Set the sprite of the drawing object.
Parameters
The new sprite.
Returns: JSGlib.Drawing.Sprite
The calling drawing object.

Text

A class representing a drawing text.
Text ( [ String text ], [ String font ], [ Number maxWidth ], [ Number lineHeight ] )
Parameters
Text to write. Use \n to insert break line. Default: ''.
Font of the text. Default: '20px Calibri'.
Maximum width of the text. If longer, break lines will automatically be included.
Default: 0 (no maximum).
Height between each line of the text. Default: 20.

draw

Draw the object. This method will be automatically called by JSGlib, you should not call it by yourself!
draw ( CanvasRenderingContext2D ctx )
Parameters
Context to draw.

font

String font ( )
Get the font of the text.
Returns: String
The font of the text.
JSGlib.Drawing.Text font ( String font )
Set the font of the text.
Parameters
The new font.
Returns: JSGlib.Drawing.Text
The calling Drawing.Text.

getHeight

Number getHeight ( )
Get the height of the text.
Returns: Number
Height of the text.

getLines

Array[String] getLines ( )
Cut the text and get its lines one by one.
Returns: Array[String]
An array containing all the lines of the text.

getWidth

Number getWidth ( )
Get the width of the text.
Returns: Number
Width of the text.

lineHeight

Number lineHeight ( )
Get the line height of the text.
Returns: Number
The line height of the text.
JSGlib.Drawing.Text lineHeight ( Number lineHeight )
Set the line height of the text.
Parameters
The new line height.
Returns: JSGlib.Drawing.Text
The calling Drawing.Text.

maxWidth

Number maxWidth ( )
Get the maximum width of the text.
Returns: Number
The maximum width of the text.
JSGlib.Drawing.Text maxWidth ( Number maxWidth )
Set the maximum width of the text.
Parameters
The new maximum width.
Returns: JSGlib.Drawing.Text
The calling Drawing.Text.

numberOfLines

Number numberOfLines ( )
Get the number of lines of the text.
Returns: Number
Number of lines of the text.

text

String text ( )
Get the text to write.
Returns: String
The text to write.
JSGlib.Drawing.Text text ( String text )
Set the text to write.
Parameters
Text to write. Use \n to insert break line.
Returns: JSGlib.Drawing.Text
The calling Drawing.Text.

Element

A class representing an element. You should not direclty use it: call Game.instanceCreate() in order to create new instances of Elements!

active

JSGlib.Element active ( Bool active )
Activate or deactivate the element.
Parameters
If true, activate the element. If false, deactivate it.
Returns: JSGlib.Element
The calling Element.
Bool active ( )
Check if the element is active.
Returns: Bool
true if element is active. false otherwise.

alwaysActive

JSGlib.Element alwaysActive ( Bool alwaysActive )
Change the "always active" state of the element. If set to true, element will be managed by JSGlib even if it's outside the view.
Parameters
New behavior.
Returns: JSGlib.Element
The calling Element.
Bool alwaysActive ( )
Check if element is always active or not.
Returns: Bool
true if element is always active. false otherwise.

callParent

Mixed callParent ( String methodName, [ Mixed/Array args ], [ String parentToCall ] )
Call the given method from given parent class on this instance.
Parameters
The name of the method to call.
Arguments to send to the called method.
If you want to send several arguments, wrap them into an array.
If you want to send only one array, you also have to wrap it into another array.
Name of the parent class having the method to use. If not specified, JSGlib will try to guess by itself.
Returns: Mixed
The return value of the called method.

cancelAlarm

Cancel the alarm having the given name.
JSGlib.Element cancelAlarm ( String/Number indexAlarm )
Parameters
Index of the alarm to cancel.
Returns: JSGlib.Element
The calling element.

cancelMoveToPointCallBack

JSGlib.Element cancelMoveToPointCallBack ( )
Unbind the callback linked with moveToPoint() method.
Returns: JSGlib.Element
The calling Element.

checkCollisions

Bool checkCollisions ( )
Check if element has to check collisions or not.
Returns: Bool
true if element has to check collisions. false otherwise.
JSGlib.Element checkCollisions ( Bool checkCollisions )
Set if element has to check collisions.
Parameters
true if element must check collisions. false otherwise.
Returns: JSGlib.Element
The calling Element.

checkMoveToPointCallback

JSGlib.Element checkMoveToPointCallback ( )
Check if the callback linked with moveToPoint() method has to be run or not.
JSGlib uses this method behind the scene, you should not call it!
Returns: JSGlib.Element
The calling Element.

destroy

Destroy the element.
JSGlib.Element destroy ( [ Bool dontTriggerEvent ] )
Parameters
If true, "eventDestroy" won't be triggered. Default: false.
Returns: JSGlib.Element
The calling Element object.

equals

Check if element is the same than the given one, checking by their id.
Bool equals ( JSGlib.Element element )
Parameters
Element to check.
Returns: Bool
true if elements are equal. false otherwise.

filter

JSGlib.Drawing.Filter filter ( )
Get the filter of the element.
Returns: JSGlib.Drawing.Filter
The filter of the element.
Element filter ( JSGlib.Drawing.Filter filter )
Set the filter of the element.
Parameters
The new filter.
Returns: Element
The calling element.

getAlarms

Get all the running alarms of the element. You don't really need to call this method: it's used behind the scenes by JSGlib!
Object getAlarms ( )
Returns: Object
An object with this kind of properties: alarmIndex => number of steps.

getCenter

Get the center of the element.
JSGlib.Point getCenter ( )
Returns: JSGlib.Point
Coordinates of center of the element.

getDirection

Number getDirection ( )
Get the direction of the element according to its hspeed and vspeed.
Returns: Number
The direction of the element, in °.

getGame

Get the game of the element.
JSGlib.Game getGame ( )
Returns: JSGlib.Game
The game where the element evolved.

getId

Get the unique id of the element.
Number getId ( )
Returns: Number
Id of the element.

getLayer

String getLayer ( )
Get the layer name of the element.
Returns: String
The layer name.

getMask

Get the rectangle representation of one of the current masks.
JSGlib.Rectangle getMask ( [ String color ] )
Parameters
Color of the mask to get.
Returns: JSGlib.Rectangle
The rectangle representation of the first mask with given color if one is provided.
The rectangle representation of the first mask found otherwise.

getRectangleRepresentation

Get the rectangle representaiton the element.
It should not be very useful to you, but JSGlib uses it internally.
JSGlib.Rectangle getRectangleRepresentation ( )
Returns: JSGlib.Rectangle
Rectangle representing the element.

gravity

Number gravity ( )
Get the gravity of the element.
Returns: Number
The gravity of the element.
JSGlib.Element gravity ( Number gravity )
Set the gravity of the element.
Parameters
The new gravity.
Returns: JSGlib.Element
The calling Element.

height

Number height ( )
Get the height of the element.
Returns: Number
The height of the element.
If the element has a sprite, the height is the one of the sprite.
JSGlib.Element height ( Number width )
Set the height of the element.
If the element has a sprite, setting its height is useless.
Parameters
The new height.
Returns: JSGlib.Element
The calling Element.

hspeed

Number hspeed ( )
Get the horizontal speed of the element.
Returns: Number
The horizontal speed of the element.
JSGlib.Element hspeed ( Number hspeed )
Set the horizontal speed of the element.
Parameters
The new horizontal speed.
Returns: JSGlib.Element
The calling Element.

instanceNearest

Get the active instance which center is the nearest of the center of this element.
JSGlib.Element instanceNearest ( [ Bool/String className ], [ Integer maxDistance ] )
Parameters
If not false, this method will check only instances of given type. Default: false.
If specified, found instance will be returned only if the distance between it and called instance is less than given value.
Returns: JSGlib.Element
The found Element, or null if none has been found.

instanceOf

Check if element is an instance of given class.
Bool instanceOf ( String className )
Parameters
Name of class to check.
Returns: Bool
true if elements an instance of given class. false otherwise.

isCollidedWithElement

Check if element is collided with given element
Object/Bool isCollidedWithElement ( JSGlib.Element element )
Parameters
Element to check.
Returns: Object/Bool
false if elements are not collided. An object containing the collided masks of each elements otherwise.

isInsideRoom

Check if element is inside current room.
Bool isInsideRoom ( )
Returns: Bool
true if element is inside current room. false otherwise.

isInsideView

Check if element is inside view.
Bool isInsideView ( )
Returns: Bool
true if element is inside view. false otherwise.

isMouseOver

Check if mouse is over element.
Bool isMouseOver ( )
Returns: Bool
true if mouse is over the element. false otherwise.

isStateDEATH

Look after the state of the element and check if it's dying or not.
Bool isStateDEATH ( )
Returns: Bool
true if element has a "DEATH" state. false otherwise.

isStateDOWN

Look after the state of the element and check if it goes down.
Bool isStateDOWN ( )
Returns: Bool
true if element has a "DOWN" state. false otherwise.

isStateHURT

Look after the state of the element and check if it's hurt or not.
Bool isStateHURT ( )
Returns: Bool
true if element has a "HURT" state. false otherwise.

isStateLEFT

Look after the state of the element and check if it goes on left.
Bool isStateLEFT ( )
Returns: Bool
true if element has a "LEFT" state. false otherwise.

isStateMOVE

Look after the state of the element and check if it's moving or not.
Bool isStateMOVE ( )
Returns: Bool
true if element has a "MOVE" state. false otherwise.

isStateRIGHT

Look after the state of the element and check if it goes on right.
Bool isStateRIGHT ( )
Returns: Bool
true if element has a "RIGHT" state. false otherwise.

isStateSLIP

Look after the state of the element and check if it's slipping or not.
Bool isStateSLIP ( )
Returns: Bool
true if element has a "SLIP" state. false otherwise.

isStateSTAND

Look after the state of the element and check if it's standing or not.
Bool isStateSTAND ( )
Returns: Bool
true if element has a "STAND" state. false otherwise.

isStateUP

Look after the state of the element and check if it goes up.
Bool isStateUP ( )
Returns: Bool
true if element has an "UP" state. false otherwise.

maskColorForSolidCollisions

JSGlib.Color maskColorForSolidCollisions ( )
Get the mask color used for collisions with solids.
Returns: JSGlib.Color
Color of the mask.
JSGlib.Element maskColorForSolidCollisions ( JSGlib.Color color )
Set the mask color used for collisions with solids.
Parameters
The color to copy.
Returns: JSGlib.Element
The calling Element.

moveToDirection

JSGlib.Element moveToDirection ( Number direction, Number speed )
Change hspeed and vspeed of the element in order to make it moving to the given direction with given speed.
Parameters
Direction to follow, in °.
Speed of movement.
Returns: JSGlib.Element
The calling Element.

moveToPoint

JSGlib.Element moveToPoint ( JSGlib.Point point, Number speed, [ Function callback ] )
Change hspeed and vspeed of the element in order to make it moving to the given point with given speed.
Parameters
Point to reach.
Speed of movement.
Function to call when element will reach the given point.
If you want to call again moveToPoint() in the callback, you MUST consider using setPath() method.
Returns: JSGlib.Element
The calling Element.

opacity

Number opacity ( )
Get the opacity of the element.
Returns: Number
The opacity of the element.
JSGlib.Element opacity ( Number opacity )
Set the opacity of the element.
Parameters
The new opacity.
Returns: JSGlib.Element
The calling Element.

position

JSGlib.Point position ( )
Get the position of the element.
Returns: JSGlib.Point
The Point object representing the position of the element.
JSGlib.Element position ( [ Number x ], [ Number y ] )
Set a new position to the element.
Parameters
Abscissa.
Ordinate.
Returns: JSGlib.Element
The calling Element.
JSGlib.Element position ( [ JSGlib.Point point ] )
Set a new position to the element.
Parameters
Point to copy.
Returns: JSGlib.Element
The calling Element.

prevPosition

JSGlib.Element prevPosition ( [ JSGlib.Point point ] )
Define the position of the element on the previous step.
This signature is used internally by JSGlib, you shouldn't use it.
Parameters
Point to copy.
Returns: JSGlib.Element
The calling Element.
JSGlib.Point prevPosition ( )
Get the position of the element on the previous step.
Returns: JSGlib.Point
The Point object representing the position of the element on the previous step.

prevX

Get the abscissa of the element on the previous step.
Number prevX ( )
Returns: Number
The abscissa of the element on the previous step.

prevY

Get the ordinate of the element on the previous step.
Number prevY ( )
Returns: Number
The ordinate of the element on the previous step.

putToFirstPlan

JSGlib.Element putToFirstPlan ( )
Put the element on the first plan of its layer.
Returns: JSGlib.Element
The calling Element object.

setAlarm

Tell the given alarm to start and finish it in the given number of steps.
JSGlib.Element/Bool setAlarm ( String/Number indexAlarm, Number numberOfSteps, [ Bool isRelative ] )
Parameters
Index of the alarm to launch.
Number of step to wait before the alarm will be finished.
If true, the second parameter will be added to the given alarm instead of replace it. Default: false.
Returns: JSGlib.Element/Bool
The calling element if "isRelative" is false.
Otherwise, a boolean indicating if the alarm is finished or not.

setPath

JSGlib.Element setPath ( Array[Object/JSGlib.Point] point, Number speed, [ String callback ] )
Change hspeed and vspeed of the element in order to make it moving to each given points.
Parameters
An array of objects containing these properties:
{
point: Instance of JSGlib.Point,
callBack: Function to call when corresponding point is reached (optional)}
If you don't want to provide a callback, you can specify an instance of JSGlib.Point without giving it via an object.
Speed of movement.
A string constant that could be one of these values:
JSGlib.KEYWORDS.REPEAT => path will be repeated once the element reaches the last point.
JSGlib.KEYWORDS.REVERSE => path will be repeated reverted once the element reaches the last point.
Returns: JSGlib.Element
The calling Element.
JSGlib.Element setPath ( Array[Object/JSGlib.Point] point, Number speed, [ Function callback ] )
Change hspeed and vspeed of the element in order to make it moving to each given points.
Parameters
An array of objects containing these properties:
{
point: Instance of JSGlib.Point,
callBack: Function to call when corresponding point is reached (optional)}
If you don't want to provide a callback, you can specify an instance of JSGlib.Point without giving it via an object.
Speed of movement.
Function to call when element will reach the last point.
Returns: JSGlib.Element
The calling Element.

solid

Bool solid ( )
Check if element is solid or not.
Returns: Bool
true if element is solid. false otherwise.
JSGlib.Element solid ( Bool solid )
Set solidity of element.
Parameters
true if element must be solid. false otherwise.
Returns: JSGlib.Element
The calling Element.

sprite

JSGlib.Sprite sprite ( )
Get the sprite of the element.
Returns: JSGlib.Sprite
The sprite of the element.
JSGlib.Element sprite ( String imageAlias, [ Number width ], [ Number height ], [ Number separation ], [ String maskAlias ] )
Set the sprite of the element.
Parameters
Alias of the image used to create the new sprite.
Width of each tile. Default: 0.
Height of each tile. Default: 0.
Separation size between each tile. Default: 0.
Alias of the image to use as mask. Default: null.
Returns: JSGlib.Element
The calling Element.
JSGlib.Element sprite ( JSGlib.Sprite sprite )
Set the sprite of the element.
Parameters
The new sprite.
Returns: JSGlib.Element
The calling Element.

spriteModified

JSGlib.Element spriteModified ( Bool modified )
Change the "modified" state of the sprite element.
JSGlib uses this signature internally, you shouldn't call it!
Parameters
New state.
Returns: JSGlib.Element
The calling Element.
Bool spriteModified ( )
Check if sprite of element has been modified.
Returns: Bool
true if sprite has been modified. false otherwise.

startPosition

Get the start position of the element.
JSGlib.Point startPosition ( )
Returns: JSGlib.Point
The Point object representing the start position of the element.

startX

Get the start abscissa of the element.
Number startX ( )
Returns: Number
The start abscissa of the element.

startY

Get the start ordinate of the element.
Number startY ( )
Returns: Number
The start ordinate of the element.

state

Number state ( )
Get the state of the element.
Returns: Number
Number representing the state: compare with JSGlib.STATE constants.
JSGlib.Element state ( Number state )
Set the state of the element.
Parameters
The new state: use JSGlib.STATE constants to manage states in an easy way!
Returns: JSGlib.Element
The calling Element.

stopOnSolids

Bool stopOnSolids ( )
Check if element has to stop on solids or not.
Returns: Bool
true if element has to stop on solids. false otherwise.
JSGlib.Element stopOnSolids ( Bool stopOnSolids )
Set if element has to stop on solids.
Parameters
true if element must stop on solids. false otherwise.
Returns: JSGlib.Element
The calling Element.

vspeed

Number vspeed ( )
Get the vertical speed of the element.
Returns: Number
The vertical speed of the element.
JSGlib.Element vspeed ( Number vspeed )
Set the vertical speed of the element.
Parameters
The new vertical speed.
Returns: JSGlib.Element
The calling Element.

width

Number width ( )
Get the width of the element.
Returns: Number
The width of the element.
If the element has a sprite, the width is the one of the sprite.
JSGlib.Element width ( Number width )
Set the width of the element.
If the element has a sprite, setting its width is useless.
Parameters
The new width.
Returns: JSGlib.Element
The calling Element.

x

Number x ( )
Get the abscissa of the element.
Returns: Number
The abscissa of the element.
JSGlib.Element x ( Number x )
Set the abscissa of the element.
Parameters
The new abcissa.
Returns: JSGlib.Element
The calling Element.

y

Number y ( )
Get the ordinate of the element.
Returns: Number
The ordinate of the element.
JSGlib.Element y ( Number y )
Set the ordinate of the element.
Parameters
The new ordinate.
Returns: JSGlib.Element
The calling Element.

zIndex

Number zIndex ( )
Get the zIndex of the element.
Returns: Number
zIndex of the element.
JSGlib.Element zIndex ( Number zIndex )
Set the zIndex of the element.
Parameters
The new zIndex.
Returns: JSGlib.Element
The calling Element object.

forceKeyUp

Force JSGlib to think that given key has been released, even if player still presses it.
Bool forceKeyUp ( Number key, [ Bool dontTriggerEvent ] )
Parameters
Key to unpress.
If true, "eventKeyUp" won't be triggered. Default: false.
Returns: Bool
true if key was pressed. false otherwise.

forEach

Iterates through a collection in order to apply a callback function to each elements.
You can break the loop by returning the value JSGlib.KEYWORDS.BREAK or continue it by returning the value JSGlib.KEYWORDS.CONTINUE.
Mixed forEach ( Array/Object collection, Function callback, [ Mixed args ] )
Parameters
Collection to iterate through.
The function to call for each elements in the collection.
Parameters to send to the called function.
If you want to send several parameters, simply send an array or an Object.
Returns: Mixed
The returned value of the callback function if this value isn't undefined.
Otherwise, it returns nothing.

Game

A class managing a game.
Game ( String idContainer, [ Number tilesSize ] )
Parameters
ID of the container of the game.
Size of tiles composing the game. Default: 16.

activateElement

Activate an element.
JSGlib.Game activateElement ( JSGlib.Element element )
Parameters
Instance to activate.
Returns: JSGlib.Game
The calling Game object.

addClass

Add a class to this game.
JSGlib.Game addClass ( Object definition )
Parameters
Definition of the new class.
{
'name': 'Name of the class (required)',
'parent': 'Name (or list of names) of class(es) to inherit from',
'abstract': Indicates if this class is abstract or not (default: false),
'eventX': function () {
//Event-method to call when event X is performed.}
'static': {
List of static methods}}
Returns: JSGlib.Game
The calling Game object.

addRooms

JSGlib.Game addRooms ( JSGlib.Room room )
Add a room to the game.
Parameters
Room to add.
Returns: JSGlib.Game
The calling Game object.
JSGlib.Game addRooms ( Array[JSGlib.Room] rooms )
Add several rooms to the game.
Parameters
List of rooms to add.
Returns: JSGlib.Game
The calling Game object.

callParent

Mixed callParent ( JSGlib.Element instance, String methodName, [ Mixed/Array args ], [ String parentToCall ] )
Call the given method from given parent class on the given instance.
Parameters
The instance affected by the call.
The name of the method to call.
Arguments to send to the called method.
If you want to send several arguments, wrap them into an array.
If you want to send only one array, you also have to wrap it into another array.
Name of the parent class having the method to use. If not specified, JSGlib will try to guess by itself.
Returns: Mixed
The return value of the called method.

callStatic

Mixed callStatic ( String className, String methodName, [ Mixed/Array args ] )
Call the given static method of given class.
Parameters
Name of the class owning the method to call.
TName of the method to call.
Arguments to send to the called method.
If you want to send several arguments, wrap them into an array.
If you want to send only one array, you also have to wrap it into another array.
Returns: Mixed
The return value of the called method.

checkElementsForActivation

JSGlib.Game checkElementsForActivation ( Bool reInitView )
Check all elements in order to activate or deactivate them.
This method is used internally by JSGlib, you shouldn't use it.
Parameters
If true, view position will be recalculated. Default: false.
Returns: JSGlib.Game
The calling Game object.

createLayer

Create a new layer in the game.
JSGlib.Game createLayer ( String name, [ Bool willContainElements ] )
Parameters
Name of the layer.
If true, indicates that layer will contain elements.
The refresh method for drawing the layer depends on its content.
Default value: false.
Returns: JSGlib.Game
The calling Game object.

deactivateElement

Deactivate an element.
JSGlib.Game deactivateElement ( JSGlib.Element element )
Parameters
Instance to deactivate.
Returns: JSGlib.Game
The calling Game object.

defaultLang

JSGlib.Game defaultLang ( String lang )
Define the default lang of the game
Parameters
The new default lang.
Returns: JSGlib.Game
The calling Game object.
String defaultLang ( )
Get the default lang of the game.
Returns: String
Default lang used by the game.

defineTranslation

Define some translations for the game.
JSGlib.Game defineTranslation ( Object definition )
Parameters
Translations definitions. Example:
{
alias: {
'fr': 'Texte français pour "alias".',
'en': 'English text for "alias".',
},
alias2: {
'fr': 'Texte français pour "alias2".',
'en': 'English text for "alias2".',
}}
Returns: JSGlib.Game
The calling Game object.

drawObject

Draw the given object on the given layer at the given position.
JSGlib.Game drawObject ( JSGlib.Drawing.Object drawingObject, String layerName, [ JSGlib.Point position ], [ Bool forceRefresh ], [ Bool eraseMode ] )
Parameters
Object to draw.
Name of the layer to draw the object.
Position where the object will be draw.
Indicate if given layer must be forced to refresh. Default: false.
If true, the drawing object will be used as a mask to erase part of the layer instead of being drawn. Default: false.
Returns: JSGlib.Game
The calling Game object.

emitEvent

JSGlib.Game emitEvent ( String eventName, [ Mixed/Array args ] )
Simulate given event in order to call corresponding event-methods for each active elements.
Parameters
Name of the event to emit.
Arguments to send to the event method.
If you want to send several arguments, wrap them into an array.
If you want to send only one array, you also have to wrap it into another array.
Returns: JSGlib.Game
The calling Game object.

eraseObject

Use the given object as a mask to erase part of the the given layer at the given position.
JSGlib.Game eraseObject ( JSGlib.Drawing.Object drawingObject, String layerName, [ JSGlib.Point position ] )
Parameters
Object to use.
Name of the layer to erase.
Position where the object will be used.
Returns: JSGlib.Game
The calling Game object.

fps

Number fps ( )
Get the FPS of the game.
Returns: Number
The FPS of the game.
JSGlib.Game fps ( Number fps )
Set the FPS of the game.
Parameters
The new FPS.
Returns: JSGlib.Game
The calling Game.

getCurrentRoom

Get the room currently running.
JSGlib.Room getCurrentRoom ( )
Returns: JSGlib.Room
The room currently running.

getImage

Get the HTML object representing the image having the given alias.
HTMLImageElement getImage ( String imageAlias )
Parameters
Alias of the image to get.
Returns: HTMLImageElement
The retreived image.

getInstanceNearest

Get the active instance which center is the nearest of the given point.
JSGlib.Element getInstanceNearest ( JSGlib.Point point, [ Bool/String className ], [ JSGlib.Element excludeInstance ], [ Integer maxDistance ] )
Parameters
Point to check.
If not false, this method will check only instances of given type. Default: false.
If specified, this method won't check given instance. Default: null.
If specified, found instance will be returned only if the distance between it and point is less than given value.
Returns: JSGlib.Element
The found Element, or null if none has been found.

getInstancesByType

Get all the active instances of given type.
Array[JSGlib.Element] getInstancesByType ( String className )
Parameters
The class name to check.
Returns: Array[JSGlib.Element]
An array containg all the found instances.

getInstancesIn

Get all the active instances inside the given rectangle area.
Array[JSGlib.Element] getInstancesIn ( JSGlib.Rectangle rectangle )
Parameters
The area to check.
Returns: Array[JSGlib.Element]
An array containg all the found instances.

getLayers

Get the names of all layers.
Array[String] getLayers ( )
Returns: Array[String]
A list containing the names of each layer.

getMouse

Get the mouse coordinates relative to the game.
JSGlib.Point getMouse ( )
Returns: JSGlib.Point
The Point objetc containing the mouse coordinates.

getRoom

Get the room having the given name.
JSGlib.Room getRoom ( )
Returns: JSGlib.Room
The corresponding room if name exists. Null otherwise.

getRooms

Get the list of rooms linked to the game.
Array[JSGlib.Room] getRooms ( )
Returns: Array[JSGlib.Room]
An array of rooms.

getScreen

Get the data URL, base64 encoded, containing the image data of the game, usefull to create screenshot.
String getScreen ( )
Returns: String
Data URL of the game, base64 encoded.

getTilesSize

Get the tiles size of this game.
Number getTilesSize ( )
Returns: Number
The tiles size.

getTileType

Get the type of tile placed at given position.
Const getTileType ( Number x, Number y, String layerName, [ String sheetName ] )
Parameters
Abscissa.
Ordinate.
Layer where the tile is drawn.
Sheet name to check on given layer. If not specified only first registered sheet will be checked.
Returns: Const
JSGlib.TILES_TYPES constant if tile exists and has a specific type. 0 otherwise.

getTranslation

Get the translated text corresponding to the given alias.
String getTranslation ( String strAlias, [ Object vars ], [ String forceLang ] )
Parameters
Alias of the text to get.
Object containing some variable to replace inside the text. Default: {}
If specified, use this lang instead of the player one.
Returns: String
The translated text.

goToFirstRoom

Launch the first room of the game.
JSGlib.Game goToFirstRoom ( )
Returns: JSGlib.Game
The calling Game object.

goToLastRoom

Launch the last room of the game.
JSGlib.Game goToLastRoom ( )
Returns: JSGlib.Game
The calling Game object.

goToNextRoom

Launch the next room of the game.
JSGlib.Game goToNextRoom ( )
Returns: JSGlib.Game
The calling Game object.

goToPrevRoom

Launch the previous room of the game.
JSGlib.Game goToPrevRoom ( )
Returns: JSGlib.Game
The calling Game object.

goToRoom

JSGlib.Game goToRoom ( String name )
Launch the given room.
Parameters
Name of the room to launch.
Returns: JSGlib.Game
The calling Game object.
JSGlib.Game goToRoom ( JSGlib.Room room )
Launch the given room.
Parameters
Room to launch.
Returns: JSGlib.Game
The calling Game object.

instanceCreate

JSGlib.Element instanceCreate ( Number x, Number y, String className, [ String layerName ] )
Create a new instance.
Parameters
Abscissa.
Ordinate.
Class name of the new element.
Layer to put the element. (default: "main")
Returns: JSGlib.Element
The created element.
JSGlib.Element instanceCreate ( JSGlib.Point point, String className, [ String layerName ] )
Create a new instance.
Parameters
Coordinates of the instance.
Class name of the new element.
Layer to put the element. (default: "main")
Returns: JSGlib.Element
The created element.

instanceDestroy

Destroy an instance.
JSGlib.Game instanceDestroy ( JSGlib.Element element, [ Bool dontTriggerEvent ] )
Parameters
Instance to destroy.
If true, "eventDestroy" won't be triggered. Default: false.
Returns: JSGlib.Game
The calling Game object.

instanceNumber

Get the number of active instances of given type.
Number instanceNumber ( String className )
Parameters
The class name to check.
Returns: Number
The total of active instances of given type.

isElementActive

Check if given element is active.
Bool isElementActive ( JSGlib.Element element )
Parameters
Element to check.
Returns: Bool
true if given element is active. false otherwise.

isElementInsideRoom

Check if given element is inside current room.
Bool isElementInsideRoom ( JSGlib.Element element )
Parameters
Element to check.
Returns: Bool
true if given element is inside current room. false otherwise.

isElementInsideView

Check if given element is inside view.
Bool isElementInsideView ( JSGlib.Element element )
Parameters
Element to check.
Returns: Bool
true if given element is inside view. false otherwise.

isMouseOver

Check if mouse is over given element.
Bool isMouseOver ( JSGlib.Element element )
Parameters
Element to check.
Returns: Bool
true if mouse is over the element. false otherwise.

isRectangleCollidedWithTiles

Check if given rectangle is collided with tiles.
Bool / Array[Object] isRectangleCollidedWithTiles ( JSGlib.Rectangle rectangle )
Parameters
Rectangle to check.
Returns: Bool / Array[Object]
false if rectangle is not collided with tiles.
Otherwise, an array of objects containing these properties:
{
number: number of the collided tile,position: position of the collided tile,type: type of the collided tile,layer: name of the layer of the collided tile}

isTileAnimated

Check if tile from given sheet with given index is animated or not.
Number/Bool isTileAnimated ( String sheetAlias, Number index )
Parameters
Name of the sheet where the tile is.
Index of the tile.
Returns: Number/Bool
Index of corresponding animation if tile is part of one. false otherwise.

isTileSlope

Check if tile from given sheet with given index is a slope or not.
Function / Bool isTileSlope ( String sheetAlias, Number index )
Parameters
Name of the sheet where the tile is.
Index of the tile.
Returns: Function / Bool
The slope function if tile is a slope. false otherwise.

load

Load given images, sounds and/or rooms.
JSGlib.Game load ( Object listRessources, [ Bool displayProgressBar ], [ Function callback ] )
Parameters
List of ressources.
{
'images': {'imageAlias': 'url_to_image'},
'sounds': {'soundAlias': ['url_to_sound', 'url2_to_sound']},
'tiles': ['url_to_tiles_definition'],
'rooms': ['url_to_file_definition']
}
'images' is an Object containing the list of images to load.
'sounds' is an Object containing the list of sounds to load : each sound must be an arraycontaining a list of URL to the same sound with different mime types (MP3, OGG etc.)
'tiles' is an Array of String representing URL to tiles definition (JSON files)
'rooms' is an Array of String representing URL to rooms definition (JSON files)
Indicates if the progress bar must be displayed or not. (default: true)
Function to call when all objects are loaded.
Returns: JSGlib.Game
The calling Game object.

muteSounds

Bool muteSounds ( )
Check is sounds are mute or not.
Returns: Bool
true if sounds are mute, false otherwise.
JSGlib.Game muteSounds ( Bool mute )
Mute or un-mute sounds.
Parameters
The new status of muting.
Returns: JSGlib.Game
The calling Game object.

orderElementsOnLayer

JSGlib.Game orderElementsOnLayer ( String layerName )
Order elements on layer with given name according to their zIndex.
Parameters
Name of the layer to request.
Returns: JSGlib.Game
The calling Game object.

orderLayers

Reorder the layers of the game.
JSGlib.Game orderLayers ( Array[String] layers )
Parameters
List of layers name to re-order.
A layer in a large index will be more foreground.
Returns: JSGlib.Game
The calling Game object.

playSound

Play the sound having the given alias.
JSGlib.Game playSound ( String soundAlias, [ Bool loop ], [ Function onEnd ] )
Parameters
Alias of the sound to play.
Indicates if the sound must be play in loop or not. Default: false.
Function to call when the sound is ended.
Returns: JSGlib.Game
The calling Game object.

putElementToFirstPlan

JSGlib.Game putElementToFirstPlan ( JSGlib.Element instance )
Put the element on the first plan of its layer.
Parameters
The instance to change.
Returns: JSGlib.Game
The calling Game object.

replayPausedSounds

Replay all sounds which have been paused.
JSGlib.Game replayPausedSounds ( )
Returns: JSGlib.Game
The calling Game object.

restartRoom

Restart the current room.
JSGlib.Game restartRoom ( )
Returns: JSGlib.Game
The calling Game object.

run

Launch the game.
JSGlib.Game run ( )
Returns: JSGlib.Game
The calling Game object.

setLayerBackgroundAlias

Define the background image for the given layer.
JSGlib.Game setLayerBackgroundAlias ( String layerName, String backgroundAlias )
Parameters
Name of the layer to request.
Alias of image to use ad background.
Returns: JSGlib.Game
The calling Game object.

setLayerBackgroundPosition

JSGlib.Game setLayerBackgroundPosition ( String layerName, Number x, [ Number y ] )
Define the init position of background for the given layer.
Parameters
Name of the layer to request.
Abscissa.
Ordinate.
Returns: JSGlib.Game
The calling Game object.
JSGlib.Game setLayerBackgroundPosition ( String layerName, JSGlib.Point point )
Define the init position of background for the given layer.
Parameters
Name of the layer to request.
Point representing the init position.
Returns: JSGlib.Game
The calling Game object.

setLayerBackgroundRepeat

Define the behavior of background-repeat for the given layer.
JSGlib.Game setLayerBackgroundRepeat ( String layerName, Number behavior )
Parameters
Name of the layer to request.
Constant from JSGlib.BACKGROUND object.
Returns: JSGlib.Game
The calling Game object.

setLayerSpeed

Define the speed of layer for parallax.
JSGlib.Game setLayerSpeed ( String layerName, Number hspeed, [ Number vspeed ] )
Parameters
Name of the layer to request.
Horizontal speed.
Vertical speed.
Returns: JSGlib.Game
The calling Game object.

setSoundVolume

Set the volume of the sound having the given alias.
JSGlib.Game setSoundVolume ( String soundAlias, Number value )
Parameters
Alias of the sound to stop.
The new volume of the sound, between 0 and 100 inclusives.
Returns: JSGlib.Game
The calling Game object.

soundIsPlaying

Check if sound with given alias is playing or not. If not alias are given, check if at least one sound is playing.
Bool soundIsPlaying ( [ String soundAlias ] )
Parameters
Alias of the sound to check.
Returns: Bool
true if sound is playing. false otherwise.
If no parameters are given, true if at least one sound is playing, false otherwise.

stopAllSounds

Stop all sounds currently playing.
JSGlib.Game stopAllSounds ( [ Bool justPause ], [ Bool runCallBack ] )
Parameters
If true, sounds will stop without re-init it. If false, sounds will stop and go back to start. Default: false.
Indicates if the "onEnd" callback linked to the sounds must be call or not. Default: false.
Returns: JSGlib.Game
The calling Game object.

stopSound

Stop the sound having the given alias if it's playing.
JSGlib.Game stopSound ( String soundAlias, [ Bool justPause ], [ Bool runCallBack ] )
Parameters
Alias of the sound to stop.
If true, sound will stop without re-init it. If false, sound will stop and go back to start. Default: false.
Indicates if the "onEnd" callback linked to the sound must be call or not. Default: false.
Returns: JSGlib.Game
The calling Game object.

toggleMuteSounds

Mute sounds if they're not mute, un-mute them if they are..
JSGlib.Game toggleMuteSounds ( )
Returns: JSGlib.Game
The calling Game object.

totalOfInstances

Get the total number of active instances.
Number totalOfInstances ( [ String className ] )
Parameters
If specified, count only instances of given type.
Returns: Number
The total of instances found.

updateMaxZIndex

JSGlib.Game updateMaxZIndex ( Number zIndex )
Update the maximum zIndex value if given value is greater than it.
Parameters
Number to check.
Returns: JSGlib.Game
The calling Game object.

getVectorDirection

Return the direction of the given vectors.
Number getVectorDirection ( Number vectorValue1, Number vectorValue1 )
Parameters
Value of first vector (typically hspeed)
Value of second vector (typically vspeed).
Returns: Number
Calculated direction, in degree.

isKeyPressed

Check if given key is pressed.
Bool isKeyPressed ( Number key )
Parameters
Key to check.
Returns: Bool
true if key is pressed. false otherwise.

isNull

Check if given value is null. This function must be used inside a forEach() callback.
Bool isNull ( Mixed value )
Parameters
Value to check.
Returns: Bool
true if value is null. false otherwise.

isset

Check if given value is not undefined and not null. This function must be used inside a forEach() callback.
Bool isset ( Mixed value )
Parameters
Value to check.
Returns: Bool
true if value is not undefined and not null. false otherwise.

isUndefined

Check if given value is undefined. This function must be used inside a forEach() callback.
Bool isUndefined ( Mixed value )
Parameters
Value to check.
Returns: Bool
true if value is undefined. false otherwise.

KEY

Object containing keyboard constants.
Values
A
ALT
B
C
CAPS_LOCK
CONTROL
CTRL
D
DOWN
E
ENTER
F
G
H
I
J
K
L
LEFT
M
N
O
P
Q
R
RIGHT
S
SHIFT
SPACE
T
TAB
U
UP
V
W
X
Y
Z

KEYWORDS

Object containing some keywords constants.
Values
BREAK
CONTINUE
NULL
REPEAT
REVERSE
UNDEFINED

Point

A class representing a point.
Point ( [ Number initX ], [ Number initY ] )
Parameters
Abscissa.
Ordinate.
Point ( [ JSGlib.Point point ] )
Parameters
Point to copy.

add

JSGlib.Point add ( [ JSGlib.Point point ] )
Add coordinates of given point to calling Point.
Parameters
Point to use.
Returns: JSGlib.Point
The calling Point.
JSGlib.Point add ( [ Number x ], [ Number y ] )
Add given coordinates to calling Point.
Parameters
Abscissa.
Ordinate.
Returns: JSGlib.Point
The calling Point.

copy

Copy coordinates of given point.
JSGlib.Point copy ( JSGlib.Point point )
Parameters
Point to copy.
Returns: JSGlib.Point
The calling Point.

equals

Check if the point has same coordinates than the given one.
Bool equals ( JSGlib.Point point )
Parameters
The point to check.
Returns: Bool
true if coordinates are equal. false otherwise.

getDistanceTo

Get the distance between this point and the given one.
Number getDistanceTo ( JSGlib.Point point )
Parameters
Point to check.
Returns: Number
The distance between both points.

isInRectangle

Check if point is in given rectangle
Bool isInRectangle ( JSGlib.Rectangle rectangle )
Parameters
Rectangle to check.
Returns: Bool
true if point is in the rectangle. false otherwise.

substract

JSGlib.Point substract ( [ JSGlib.Point point ] )
Substract coordinates of given point to calling Point.
Parameters
Point to use.
Returns: JSGlib.Point
The calling Point.
JSGlib.Point substract ( [ Number x ], [ Number y ] )
Substract given coordinates to calling Point.
Parameters
Abscissa.
Ordinate.
Returns: JSGlib.Point
The calling Point.

x

Number x ( )
Get the abscissa of the point.
Returns: Number
The abscissa of the point.
JSGlib.Point x ( Number x )
Set the abscissa of the point.
Parameters
The new abcissa.
Returns: JSGlib.Point
The calling Point.

y

Number y ( )
Get the ordinate of the point.
Returns: Number
The ordinate of the point.
JSGlib.Point y ( Number y )
Set the ordinate of the point.
Parameters
The new ordinate.
Returns: JSGlib.Point
The calling Point.

random

Generates a random interger.
Number random ( Number min, Number max )
Parameters
Minimum inclusive value, can be negative.
Maximum inclusive value, can be negative.
Returns: Number
The generated integer.

Rectangle

A class representing a rectangle.
Rectangle ( [ Number initX ], [ Number initY ], [ Number initWidth ], [ Number initHeight ] )
Parameters
Abscissa.
Ordinate.
Width.
Height.
Rectangle ( [ JSGlib.Point point ], [ Number initWidth ], [ Number initHeight ] )
Parameters
Point to copy.
Width.
Height.
Rectangle ( [ JSGlib.Rectangle rectangle ] )
Parameters
Rectangle to copy.

getCenter

Get the center of the rectangle.
JSGlib.Point getCenter ( )
Returns: JSGlib.Point
Coordinates of center of the rectangle.

height

Number height ( )
Get the height of the rectangle.
Returns: Number
The height of the rectangle.
JSGlib.Rectangle height ( Number height )
Set the height of the rectangle.
Parameters
The new height.
Returns: JSGlib.Rectangle
The calling Rectangle.

isCollidedWithRectangle

Check if rectangle is collided with given rectangle
Bool isCollidedWithRectangle ( JSGlib.Rectangle rectangle )
Parameters
Rectangle to check.
Returns: Bool
true if rectangles are collided. false otherwise.

position

JSGlib.Point position ( )
Get the position of the rectangle.
Returns: JSGlib.Point
The Point object representing the position of the rectangle.
JSGlib.Rectangle position ( [ Number x ], [ Number y ] )
Set a new position to the rectangle.
Parameters
Abscissa.
Ordinate.
Returns: JSGlib.Rectangle
The calling Rectangle.
JSGlib.Rectangle position ( JSGlib.Point point )
Set a new position to the rectangle.
Parameters
Point to copy.
Returns: JSGlib.Rectangle
The calling Rectangle.

width

Number width ( )
Get the width of the rectangle.
Returns: Number
The width of the rectangle.
JSGlib.Rectangle width ( Number width )
Set the width of the rectangle.
Parameters
The new width.
Returns: JSGlib.Rectangle
The calling Rectangle.

x

Number x ( )
Get the abscissa of the rectangle.
Returns: Number
The abscissa of the rectangle.
JSGlib.Rectangle x ( Number x )
Set the abscissa of the rectangle.
Parameters
The new abcissa.
Returns: JSGlib.Rectangle
The calling Rectangle.

y

Number y ( )
Get the ordinate of the rectangle.
Returns: Number
The ordinate of the rectangle.
JSGlib.Rectangle y ( Number y )
Set the ordinate of the rectangle.
Parameters
The new ordinate.
Returns: JSGlib.Rectangle
The calling Rectangle.

removeFromArray

Remove given element from given array.
Bool removeFromArray ( Mixed element, Array array, [ Function callback ] )
Parameters
Element to remove.
Array to scan.
Function to use in order to compare elements.
It must accept two parameters and return a boolean.
Returns: Bool
true if the element was removed. false otherwise.

Room

A class representing a room.
Room ( String name, Number width, Number height )
Parameters
Name of the room.
Width of the room.
Height of the room.

eventStart

Event method called after the room is starting.

getHeight

Get the height of the room.
Number getHeight ( )
Returns: Number
Height of the room.

getName

Get the name of the room.
String getName ( )
Returns: String
Name of the room.

getWidth

Get the width of the room.
Number getWidth ( )
Returns: Number
Width of the room.

view

JSGlib.Rectangle view ( )
Get the view of the room.
Returns: JSGlib.Rectangle
View of the room.
JSGlib.Room view ( Number initX, [ Number initY ], [ Number initWidth ], [ Number initHeight ] )
Set the view of the room.
Parameters
Abscissa.
Ordinate.
Width.
Height.
Returns: JSGlib.Room
The calling Room object.
JSGlib.Room view ( JSGlib.Point point, [ Number initWidth ], [ Number initHeight ] )
Set the view of the room.
Parameters
Point to copy.
Width.
Height.
Returns: JSGlib.Room
The calling Room object.
JSGlib.Room view ( JSGlib.Rectangle rectangle )
Set the view of the room.
Parameters
Rectangle to copy.
Returns: JSGlib.Room
The calling Room object.

viewLinkedElement

JSGlib.Room viewLinkedElement ( JSGlib.Element element )
Define an element which will be followed by the view.
Parameters
The element to follow.
Returns: JSGlib.Room
The calling Room.
JSGlib.Element viewLinkedElement ( )
Get the element followed by the view.
Returns: JSGlib.Element
The followed element.

Sprite

A class representing a sprite.
Sprite ( HTMLImageElement image )
Parameters
HTML image to use as sprite.

animate

Change the tile to display for this sprite via its image speed.
Mixed animate ( )
Returns: Mixed
true if tile has been changed and animation is finished.
false if tile has been changed and animation is NOT finished.Null if tile has not been changed.

getCurrentMasks

Get the masks corresponding to the current tile.
Array getCurrentMasks ( )
Returns: Array
A list of JSON object containing the masks of the current tile.

getCurrentTileNumber

Get the number of tile currently displayed.
Number getCurrentTileNumber ( )
Returns: Number
Number of the tile.

getCurrentTilePosition

Get the position of the tile in the whole image.
JSGlib.Point getCurrentTilePosition ( )
Returns: JSGlib.Point
Point representing the coordinates of the tile.

getHeight

Get the height of the sprite.
Number getHeight ( )
Returns: Number
Height of the sprite.

getImage

Get the image of the sprite.
HTMLImageElement getImage ( )
Returns: HTMLImageElement
Image used as sprite.

getTilesHeight

Get the height of the tiles contained in the sprite.
Number getTilesHeight ( )
Returns: Number
Height of the tiles.

getTilesSeparation

Get the separation size bewteen tiles.
Number getTilesSeparation ( )
Returns: Number
The separation size, in pixels.

getTilesWidth

Get the width of the tiles contained in the sprite.
Number getTilesWidth ( )
Returns: Number
Width of the tiles.

getWidth

Get the width of the sprite.
Number getWidth ( )
Returns: Number
Width of the sprite.

imageindex

Number imageindex ( )
Get the index of animation.
Returns: Number
The index of the animation.
JSGlib.Sprite imageindex ( Number imageindex )
Set the index of the animation.
JSGlib uses this signature internally, you shouldn't call it!
Parameters
The new index of animation.
Returns: JSGlib.Sprite
The calling Sprite.

imagespeed

Number imagespeed ( )
Get the speed animation of the sprite.
Returns: Number
The speed animation.
JSGlib.Sprite imagespeed ( Number imagespeed )
Set the speed animation of the sprite.
Parameters
The new speed animation.
Returns: JSGlib.Sprite
The calling Sprite.

isTiles

Check if Sprite is divided into tiles.
Bool isTiles ( )
Returns: Bool
true if Sprite contains tiles. false otherwise.

makeTiles

Divide the sprite into several tiles.
JSGlib.Sprite makeTiles ( Number width, Number height, [ Number separation ] )
Parameters
Width of each tile.
Height of each tile.
Separation size between each tile. Default: 0.
Returns: JSGlib.Sprite
The calling Sprite object.

masks

JSGlib.Sprite masks ( HTMLImageElement maskAlias )
Analyse the given image to create the collisions mask of the sprite.
Parameters
The image to analyse.
Returns: JSGlib.Sprite
The calling Sprite.
Array masks ( )
Get the collisions mask of the sprite.
Returns: Array
Collisions mask of the sprite.

usedTiles

Array[Number] usedTiles ( )
Get the index number of tiles used for animation of this sprite.
Returns: Array[Number]
An array containing the list of tiles numbers.
JSGlib.Sprite usedTiles ( Array[Number] tiles )
Set the list of tiles to use for animate the sprite.
Parameters
An array containing the list of tiles numbers to use.
Returns: JSGlib.Sprite
The calling Sprite.

STATE

Object containing states constants for development help.
Values
DEATH
DEATH_DOWN
DEATH_DOWN_LEFT
DEATH_DOWN_RIGHT
DEATH_LEFT
DEATH_RIGHT
DEATH_UP
DEATH_UP_LEFT
DEATH_UP_RIGHT
HURT
HURT_DOWN
HURT_DOWN_LEFT
HURT_DOWN_RIGHT
HURT_LEFT
HURT_RIGHT
HURT_UP
HURT_UP_LEFT
HURT_UP_RIGHT
MOVE
MOVE_DOWN
MOVE_DOWN_LEFT
MOVE_DOWN_RIGHT
MOVE_LEFT
MOVE_RIGHT
MOVE_UP
MOVE_UP_LEFT
MOVE_UP_RIGHT
SLIP
SLIP_DOWN
SLIP_DOWN_LEFT
SLIP_DOWN_RIGHT
SLIP_LEFT
SLIP_RIGHT
SLIP_UP
SLIP_UP_LEFT
SLIP_UP_RIGHT
STAND
STAND_DOWN
STAND_DOWN_LEFT
STAND_DOWN_RIGHT
STAND_LEFT
STAND_RIGHT
STAND_UP
STAND_UP_LEFT
STAND_UP_RIGHT

TILES_TYPES

Object containing tiles types constants.

uniqueArray

Remove duplicated content in given array.
Array uniqueArray ( Array array, [ Bool isArrayOfElements ] )
Parameters
Array to scan.
If true, indicates that given array contains JSGlib.Element.
If false, indicates that given array contains only primitive values.
Default: false.
Returns: Array
The new array.

USER_LANG

Lang using by player's browser.