This provides a basic camera.
You can also create your own camera type if you wish. To do so, have a look at the source of this file.
A camera that always shows the same area. This is useful in a top down game. This means that you probably want to specify the area property like this:
fixedArea (16*10) (x, y)This would show 16 by 10 units IF the game is displayed in a 16:10 viewport. But in a 4:3 viewport it would show sqrt(16104/3)=14.6 by sqrt(16103/4)=10.95 units.
A camera that always shows width units of your game horizontally.
Well suited for a side-scroller.
A camera that always shows height units of your game vertically.
Well suited for a vertical scroller.
The custom camera allows you to use a function that maps viewport size (in pixel) to game units. E.g. here's an implementation of the fixedWidth camera using custom:
fixedWidth width =
custom (\(w, h) -> (width, width * h / w))Move a camera by the given vector relative to the camera.
Move a camera to the given location. In absolute coordinates.
Smoothly follow the given target. Use this in your tick function.
follow 1.5 dt target cameraGets the transformation that represents how to transform the camera back to the origin. The result of this is used in the vertex shader.
Given the screen size, gets the width and height in game units
A camera represents how to render the virtual world. It's essentially a transformation from virtual game coordinates to pixel coordinates on the screen.