Have you ever been frustrated when converting screen to world coordinates in a game with a camera? Have you ever wished it was simple to get a camera to smoothly follow a game object while also having a defined dead zone?
The Orthographic Camera API is designed to simplify these and other camera related functions. Using it in your 2D game is super simple:
- Add the
camera.go
to your game - Make sure your render script handles the
set_view_projection
message properly - Interact with the camera either via the
camera
module or via messages to thecamera.go
The API :
local camera = require "orthographic.camera"
local world = camera.screen_to_world(camera_id, screen)
camera.shake(camera_id, [intensity], [duration], [direction], [cb])
camera.follow(camera_id, target, [lerp])
camera.unfollow(camera_id)
camera.deadzone(camera_id, left, top, right, bottom)
The camera API is inspired by the Phaser camera component.
CODE: https://github.com/britzl/defold-orthographic
DEMO: http://britzl.github.io/publicexamples/orthographic/index.html
TODO:
- Add functionality to do culling of game objects outside camera view
- Add functionality to specify camera bounds