API Document Index



Class me.game


Defined in: <build/melonJS-0.9.3.js>.

Class Summary
Constructor Attributes Constructor Name and Description
 
me.game represents your current game, it contains all the objects, tilemap layers,
HUD information, current viewport, collision map, etc.
Field Summary
Field Attributes Field Name and Description
<constant>  
Default object type constant.
<constant>  
Default object type constant.
 
a reference to the game collision Map
 
a reference to the game current level
<constant>  
Default object type constant.
 
HUD
a reference to the game HUD (if defined).
 
Fired when a level is fully loaded and
and all entities instantiated.
 
a reference to the game viewport.
Method Summary
Method Attributes Method Name and Description
 
add(obj, z)
Manually add object to the game manager
 
addHUD(x, y, w, h, bg)
add a HUD obj to the game manager
 
collide(obj)
check for collision between objects
 
disable the current HUD
 
return the entity corresponding to the specified GUID
note : avoid calling this function every frame since it parses the whole object list each time
 
getEntityByName(entityName)
returns the list of entities with the specified name
as defined in Tiled (Name field of the Object Properties)
note : avoid calling this function every frame since it parses the whole object list each time
 
remove(obj)
remove an object
 
remove all objects
 
force the redraw (not update) of all objects
 
reset the game Object manager

destroy all current object except the HUD

 
sort()

Sort all objects (using object z property value).

Class Detail
me.game()
me.game represents your current game, it contains all the objects, tilemap layers,
HUD information, current viewport, collision map, etc..
me.game is also responsible for updating (each frame) the object status and draw them
There is no constructor function for me.game.
Field Detail
<constant> ACTION_OBJECT
Default object type constant.
See type property of the returned collision vector.

<constant> COLLECTABLE_OBJECT
Default object type constant.
See type property of the returned collision vector.

{me.TiledLayer} collisionMap
a reference to the game collision Map

{me.TMXTileMap} currentLevel
a reference to the game current level

<constant> ENEMY_OBJECT
Default object type constant.
See type property of the returned collision vector.

{me.HUD_Object} HUD
a reference to the game HUD (if defined).

{function} onLevelLoaded
Fired when a level is fully loaded and
and all entities instantiated.
Additionnaly the level id will also be passed to the called function.
call myFunction() everytime a level is loaded
me.game.onLevelLoaded = this.myFunction.bind(this);

{me.Viewport} viewport
a reference to the game viewport.
Method Detail
add(obj, z)
Manually add object to the game manager
// create a new object
var obj = new MyObject(x, y)
// add the object and give the z index of the current object
me.game.add(obj, this.z);
// sort the object list (to ensure the object is properly displayed)
me.game.sort();
Parameters:
{me.ObjectEntity} obj
Object to be added
{int} z Optional, Default: "obj.z"
z index

addHUD(x, y, w, h, bg)
add a HUD obj to the game manager
Parameters:
{int} x
x position of the HUD
{int} y
y position of the HUD
{int} w
width of the HUD
{int} h
height of the HUD
{String} bg Optional, Default: "none"
a CSS string specifying the background color (e.g. "#0000ff" or "rgb(0,0,255)")

{me.Vector2d} collide(obj)
check for collision between objects
// update player movement
this.updateMovement();

// check for collision with other objects
res = me.game.collide(this);

// check if we collide with an enemy :
if (res && (res.obj.type == me.game.ENEMY_OBJECT))
{ 	
  if (res.x != 0)
  {
     // x axis
     if (res.x<0)
        console.log("x axis : left side !");
     else
        console.log("x axis : right side !");
  }
  else
  {
     // y axis
     if (res.y<0)
        console.log("y axis : top side !");
     else
        console.log("y axis : bottom side !");			
  }
}
Parameters:
{me.ObjectEntity} obj
Object to be tested for collision
Returns:
{me.Vector2d} collision vector me.Rect#collideVsAABB

disableHUD()
disable the current HUD

{me.ObjectEntity} getEntityByGUID(GUID)
return the entity corresponding to the specified GUID
note : avoid calling this function every frame since it parses the whole object list each time
Parameters:
{String} GUID
entity GUID
Returns:
{me.ObjectEntity} Object Entity (or null if not found)

{me.ObjectEntity[]} getEntityByName(entityName)
returns the list of entities with the specified name
as defined in Tiled (Name field of the Object Properties)
note : avoid calling this function every frame since it parses the whole object list each time
Parameters:
{String} entityName
entity name
Returns:
{me.ObjectEntity[]} Array of object entities

remove(obj)
remove an object
Parameters:
{me.ObjectEntity} obj
Object to be removed

removeAll()
remove all objects

repaint()
force the redraw (not update) of all objects

reset()
reset the game Object manager

destroy all current object except the HUD

See:
me.game#disableHUD

sort()

Sort all objects (using object z property value).

Normally all objects loaded through the LevelDirector are automatically sorted. this function is however usefull if you create and add object during the game.


Documentation generated by JsDoc Toolkit 2.4.0 on Tue May 01 2012 12:00:49 GMT+0800 (CST)