new State()
Object acting as a container of game objects. It helps structure the game in
states.
Members
-
<static> lastId :int
-
Static attributes used to store the last ID affected to a game object.
Type:
- int
-
camera :FM.Rectangle
-
Camera (limited by the screen resolution of the game).
Type:
-
members :Array
-
Array containing every game objects of the state.
Type:
- Array
Methods
-
add(gameObject)
-
Add a game object to the state.
Parameters:
Name Type Description gameObject
FM.GameObject The game object to add to the state. -
centerCameraAt(xPosition, yPosition)
-
Center the camera at a specific given position.
Parameters:
Name Type Description xPosition
int The target x position of the camera. yPosition
int The target y position of the camera. -
centerCameraOn(gameObject)
-
Center the camera on a specific game object.
Parameters:
Name Type Description gameObject
FM.GameObject The game object to center the camera on. -
destroy()
-
Destroy the state and its objects.
-
draw(bufferContext, dt)
-
Draw the game objects of the state.
Parameters:
Name Type Description bufferContext
CanvasRenderingContext2D Context (buffer) on wich drawing is done. dt
float Variable delta time since the last frame. -
follow(gameObject, width, height)
-
Make an object as the scroller.
Parameters:
Name Type Description gameObject
FM.GameObject The game object to follow. width
int The width of the camera. height
int The height of the camera. -
getGameObjectById(pId) → {FM.GameObject}
-
Get the game object which ID matches the one given.
Parameters:
Name Type Description pId
int The ID of the object to retrieve. Returns:
The game object that corresponds or null if it finds nothing.- Type
- FM.GameObject
-
getQuad() → {FM.QuadTree}
-
Get the quad tree.
Returns:
The quad tree containing every game object with a physic component.- Type
- FM.QuadTree
-
getScroller() → {FM.GameObject}
-
Get the object that scrolls the screen.
Returns:
The game object that scrolls the screen.- Type
- FM.GameObject
-
getWorld() → {FM.World}
-
Get the world object.
Returns:
The world of the game.- Type
- FM.World
-
init(pWorldWidth, pWorldHeight)
-
Initialize the state. Can be redefined in sub classes for specialization.
Parameters:
Name Type Description pWorldWidth
int The width of the world to create. pWorldHeight
int The height of the world to create. -
remove(gameObject)
-
Remove an object from the state and destroy it.
Parameters:
Name Type Description gameObject
FM.GameObject The game object to remove and destroy. -
sortByZIndex()
-
Sort the members of the state by their z-index.
-
unFollow()
-
Delete the scroller.
-
update(dt)
-
Update the game objects of the state.
Parameters:
Name Type Description dt
float The fixed delta time in seconds since the last frame. -
updatePhysics(dt)
-
Update the game physics.
Parameters:
Name Type Description dt
float The fixed delta time in seconds since the last frame.