The camera class.
Every gamvas.State has a default camera, which you can access with this.camera
new gamvas.Camera([x], [y], [rot], [zoom]);
x/y | The position of the cameras center (optional) |
rot | The rotation of the camera in radians (optional) |
zoom | The zoom factor of the camera (optional) |
gamvas. | The camera class. |
Variables | |
position | A gamvas.Vector2D object that holds the position of the camera. |
rotation | The rotation of the camera in radians. |
zoomFactor | The zoom factor of the camera. |
Functions | |
setPosition | Set the position of the camera to absolute values. |
move | Move the camera, relative to its current position. |
setRotation | Set the rotation to a specific degree in radians |
rotate | Rotate the camera for r radians |
setZoom | Set a specific zoom level to the camera. |
zoom | Zoom the camera |
start | Start the camera. |
stop | Stop the camera, everything drawn from now on will not be under the influence of the camera. |
toWorld | Convert screen coordinates to world coordinates. |
toScreen | Convert world coordinates to screen coordinates. |
this.position
A gamvas.Vector2D object that holds the position of the camera. It is recommended to use it only for reading.
gamvas.Camera.prototype.start = function()
Start the camera. Needs to be called before every drawing operation that should be in the influence of the camera (e.g. your game actors)
this.camera.start(); // draw everything under camera influence this.drawGameObjects(); this.camera.stop(); // draw everything not under camera influence (e.g. Score, Health, ...) this.drawHUD();
gamvas.Camera.prototype.toWorld = function( x, y )
Convert screen coordinates to world coordinates. For example if you have a rotated camera and the user clicks on the screen, use this function to check which position the click on the rotated camera is in the unrotated world.
A gamvas.Vector2D object that holds the position of the camera.
this.position
The rotation of the camera in radians.
this.rotation
The zoom factor of the camera.
this.zoomFactor
Set the position of the camera to absolute values.
gamvas.Camera.prototype.setPosition = function( x, y )
Move the camera, relative to its current position.
gamvas.Camera.prototype.move = function( x, y )
Set the rotation to a specific degree in radians
gamvas.Camera.prototype.setRotation = function( r )
Rotate the camera for r radians
gamvas.Camera.prototype.rotate = function( r )
Set a specific zoom level to the camera.
gamvas.Camera.prototype.setZoom = function( z )
Zoom the camera
gamvas.Camera.prototype.zoom = function( z )
Start the camera.
gamvas.Camera.prototype.start = function()
Stop the camera, everything drawn from now on will not be under the influence of the camera.
gamvas.Camera.prototype.stop = function()
Convert screen coordinates to world coordinates.
gamvas.Camera.prototype.toWorld = function( x, y )
Convert world coordinates to screen coordinates.
gamvas.Camera.prototype.toScreen = function( x, y )