xCamera
A downloadable asset pack
[INFO]
This is a task based 2D Camera asset pack for GMS2.3+.
[SETUP]
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)
// Create a camera at position 0,0 attached to view 0 camera = new Camera(0, 0, 0); // This will make the camera follow the player. camera.follow(objPlayer); // Limit the camera to the room. camera.limit(0,0,room_width,room_height)
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 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.
- follow: follows an instance or object type [instance/object]
- focus: focus on a point [x, y]
- lock: locks movement for given axis [horizontal, vertical]
- zoom: zooms the camera to x amount [target, duration, callback] (*)
- limit: limits the camera placement to a region [x1, y1, x2, y2]
- shake: shakes the camera [amount, duration, callback] (*)
- flash: creates a flash [color, interval, duration, callback] (*)
(*) 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):
// Prevent the auto-load from executing camera = new Camera(0, 0, 0, false); // ... // This method should be called manually every step (*) camera.update()
(*) 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) // Follow the player. camera.follow() // This will terminate the camera task. camera.follow(noone) // Will also terminate the camera 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
- cm_lerp: lerps between the position (0 - 1, higher is faster), defaults to 0.2
- cm_fixed: moves by fixed pixel amount (0 - max, higher is faster), defaults to 15
- cm_damped: smooth ease in-out move (0 - max, higher is smooth), defaults to 25
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.
[NOTES]
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.
[COMPATIBILITY]
The asset is fully compatible with 2.3+ and is purely written in GML making it compatible with all exports available.
[TERMS OF PURCHASE]
- You will receive free updates as they release on this website.
- The price may vary based on the marketplace.
- Support, bug fix will be handled on a case-by-case basis at earliest possible.
- No parts of your purchase may be re-distributed, re-sold, or bundled with existing assets.
Download
Click download now to get access to the following files:
Comments
Log in with itch.io to leave a comment.
Hello,
I'm very interested by your asset but as usual when I find a Camera extension I have to ask one thing only :
Is it possible and easy to implement it with splitscreen (e.g multiple viewport) ?
Looking to how you have to link a camera to a view, I tend to think it's the case, but I prefer to be sure :D
Thank you.