36 setCam - JcerelusDev/CanvasGameJs GitHub Wiki
What is the setCam method
The setCam is used to center the camera to the player position, so that the camera will follow the player around the game world.
SetCam method should be used before you draw anything in the drawGame function.
Use that method only if needed.
setCam method has 3 arguments :
game.setCam(player,world,debug)
1.- the player or main character
2.- world is the world to be explored by the player. It could be a large background image or your map if it is a tile based game.
If the map is created by hand.
var map = [
[0,0,1,0],
[0,1,0,1],
[0,0,0,0]
]
var world = game.worldThrouhCamera()
if it was created with tiled in your json file you will get : the width and tilewidth values,
the height and tileheight values
var world = game.worldThrouhCamera()
3.- debug (optional only for debugging the camera) is a boolean if it is set to true it will draw the camera.
Example :
Considering we are using the same player object and game object
var world = game.worldThrouhCamera()
game.render = function(){
game.setCam(player,world )
// then draw everything after setCam
}