API Document Index



Class me.ObjectEntity


Extends me.AnimationSheet.

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

Class Summary
Constructor Attributes Constructor Name and Description
 
me.ObjectEntity(x, y, settings)
a Generic Object Entity
Object Properties (settings) are to be defined in Tiled,
or when calling the parent constructor
Field Summary
Field Attributes Field Name and Description
 
entity current acceleration
 
dead/living state of the entity
default value : true
 
Define if an entity can go through breakable tiles
default value : false
 
falling state of the object
true if the object is falling
false if the object is standing on something
(!) READ ONLY property
 
entity current friction
 
Default gravity value of the entity
default value : 0.98 (earth gravity)
to be set to 0 for RPG, shooter, etc.
 
Entity "Game Unique Identifier"
 
jumping state of the object
equal true if the entity is jumping
(!) READ ONLY property
 
max velocity (to limit entity velocity)
 
equal true if the entity is on a ladder
(!) READ ONLY property
 
equal true if the entity is standing on a slope
(!) READ ONLY property
 
a callback when an entity break a tile
 
vel
entity current velocity
Fields borrowed from class me.AnimationSheet:
animationspeed
Fields borrowed from class me.SpriteObject:
autodestroy, visible
Fields borrowed from class me.Rect:
bottom, height, left, pos, right, top, width
Method Summary
Method Attributes Method Name and Description
 
distanceTo(entity)
return the distance to the specified entity
 
doClimb(up)
helper function for platform games:
make the entity move up and down
only valid is the player is on a ladder
 
helper function for platform games:
make the entity jump
 
doWalk(left)
helper function for platform games:
make the entity move left of right
 
helper function for platform games:
force to the entity to jump (for double jump)
 
onCollision(res, obj)
onCollision Event function
called by the game manager when the object collide with shtg
by default, if the object type is Collectable, the destroy function is called
 
set the entity default friction
 
cap the entity velocity to the specified value
(!) this will only cap the y velocity for now(!)
 
set the entity default velocity
note : velocity is by default limited to the same value, see setMaxVelocity if needed
 
updateColRect(x, w, y, h)
specify the size of the hit box for collision detection
(allow to have a specific size for each object)
e.g.
 
handle the player movement, "trying" to update his position
Methods borrowed from class me.AnimationSheet:
addAnimation, isCurrentAnimation, setAnimationFrame, setCurrentAnimation, update
Methods borrowed from class me.SpriteObject:
draw, flicker, flipX, flipY, isFlickering, onDestroyEvent, resize, setTransparency
Methods borrowed from class me.Rect:
contains, containsPoint, getRect, overlaps, set, union, within
Class Detail
me.ObjectEntity(x, y, settings)
a Generic Object Entity
Object Properties (settings) are to be defined in Tiled,
or when calling the parent constructor
Parameters:
{int} x
the x coordinates of the sprite object
{int} y
the y coordinates of the sprite object
{me.ObjectSettings} settings
Object Properties as defined in Tiled
Field Detail
{me.Vector2d} accel
entity current acceleration

{Boolean} alive
dead/living state of the entity
default value : true

{Boolean} canBreakTile
Define if an entity can go through breakable tiles
default value : false

{Boolean} falling
falling state of the object
true if the object is falling
false if the object is standing on something
(!) READ ONLY property

{me.Vector2d} friction
entity current friction

{Number} gravity
Default gravity value of the entity
default value : 0.98 (earth gravity)
to be set to 0 for RPG, shooter, etc...

{String} GUID
Entity "Game Unique Identifier"

{Boolean} jumping
jumping state of the object
equal true if the entity is jumping
(!) READ ONLY property

{me.Vector2d} maxVel
max velocity (to limit entity velocity)

{Boolean} onladder
equal true if the entity is on a ladder
(!) READ ONLY property

{Boolean} onslope
equal true if the entity is standing on a slope
(!) READ ONLY property

{Function} onTileBreak
a callback when an entity break a tile

{me.Vector2d} vel
entity current velocity
Method Detail
{float} distanceTo(entity)
return the distance to the specified entity
Parameters:
{me.ObjectEntity} entity
Entity
Returns:
{float} distance

doClimb(up)
helper function for platform games:
make the entity move up and down
only valid is the player is on a ladder
if (me.input.isKeyPressed('up'))
{
    this.doClimb(true);
}
else if (me.input.isKeyPressed('down'))
{
    this.doClimb(false);
}
Parameters:
{Boolean} up
will automatically flip vertically the entity sprite

doJump()
helper function for platform games:
make the entity jump

doWalk(left)
helper function for platform games:
make the entity move left of right
if (me.input.isKeyPressed('left'))
{
    this.doWalk(true);
}
else if (me.input.isKeyPressed('right'))
{
    this.doWalk(false);
}
Parameters:
{Boolean} left
will automatically flip horizontally the entity sprite

forceJump()
helper function for platform games:
force to the entity to jump (for double jump)

onCollision(res, obj)
onCollision Event function
called by the game manager when the object collide with shtg
by default, if the object type is Collectable, the destroy function is called
Parameters:
{me.Vector2d} res
collision vector
{me.ObjectEntity} obj
the other object that hit this object

setFriction(x, y)
set the entity default friction
Parameters:
{Int} x
horizontal friction
{Int} y
vertical friction

setMaxVelocity(x, y)
cap the entity velocity to the specified value
(!) this will only cap the y velocity for now(!)
Parameters:
{Int} x
max velocity on x axis
{Int} y
max velocity on y axis

setVelocity(x, y)
set the entity default velocity
note : velocity is by default limited to the same value, see setMaxVelocity if needed
Parameters:
{Int} x
velocity on x axis
{Int} y
velocity on y axis

updateColRect(x, w, y, h)
specify the size of the hit box for collision detection
(allow to have a specific size for each object)
e.g. : object with resized collision box :
Parameters:
{int} x
x offset (specify -1 to not change the width)
{int} w
width of the hit box
{int} y
y offset (specify -1 to not change the height)
{int} h
height of the hit box

{me.Vector2d} updateMovement()
handle the player movement, "trying" to update his position
// make the player move
if (me.input.isKeyPressed('left'))
{
    this.vel.x -= this.accel.x * me.timer.tick;
}
else if (me.input.isKeyPressed('right'))
{
    this.vel.x += this.accel.x * me.timer.tick;
}
// update player position
var res = this.updateMovement();

// check for collision result with the environment
if (res.x != 0)
{
  // x axis
  if (res.x<0)
     console.log("x axis : left side !");
  else
     console.log("x axis : right side !");
}
else if(res.y != 0)
{
   // y axis
   if (res.y<0)
      console.log("y axis : top side !");
   else
      console.log("y axis : bottom side !");		
		
	  // display the tile type
   console.log(res.yprop.type)
}

// check player status after collision check
var updated = (this.vel.x!=0 || this.vel.y!=0);
Returns:
{me.Vector2d} a collision vector

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