In order to use the camera system first you need to setup the view/camera as normal in the IDE using the room settings. After that you just need to call the camera constructor with the given view and that's it (see the example code just below)
camera = new Camera(0, 0, 0); // This will create a camera from view 0 and place it at position (0, 0) camera.follow(oPlayer); // This will make the camera follow the player. camera.limit(0,0,room_width,room_height) // This will limit the camera movement to the room.
This can be done inside a persistent managing object (objGame) to avoid creating multiple cameras (which can leading to memory leaks).
[USAGE] This system uses a task approach meaning each function you want the camera to do is a CameraTask. Upon creating a camera instance connected to a view you just need to call the desired methods on the camera to execute task.
(*) This tasks are special tasks the inherit from CameraTimedTask which means they will occur over a X amount of time (in seconds). After that time the task is automatically removed from the task stack. Theses tasks can also be given a callback to be executed when they reach the end.
The tasked above are displayed by ascending priority order this means tasks have a fixed execution order despite the order they are added in. The 'focus' task has a higher priority than the 'follow' task if the camera is given both tasks the focus tasks will be the one contributing the to final camera position and the follow will be overwritten.
This system by default an automatic way of controlling and executing its tasks meaning you don't have to call update/step or any other method for it to work however if you need extra control you can disable this mode in the constructor of the camera (or using the setAutoload(enabled) method):
camera = new Camera(0, 0, 0, false); // This will prevent the autoload from executing // ... camera.update() // This method should be called manually every step (*)
(*) Take into account that given that some tasks require drawing to the screen (ie.: flash) you might need to call update inside a draw event.
If you need to terminate any of the default tasks you can call the respective function with no arguments:
camera.follow(oPlayer) // This will make the camera follow the player. camera.follow() // This will terminate the camera follow task. camera.follow(noone) // Will also terminate the camera follow task.
Finally this camera system provides 3 movement modes, these modes can be exchanged whenever you see fit using the method 'setMoveType' and providing a movement constant and an amount of move effect
These are the default builtin functionalities of the xCamera system as is. Please read all the function documentation as they are fully documented which makes it easier to understand how everything works. I also included a note with a more detailed approach on the implementation as well as how to expand this system by creating your own tasks.
The demo project serves as an example for the Camera system meaning that code for movement and collisions should not be considered as a robust approach.
The asset is fully compatible with 2.3+ and is purely written in GML making it compatible with all exports available.
[TERMS OF PURCHASE]
Reworked the demo project for enhanced compatibility across platforms.