Asset - Scripts [CAMERA] xCamera is a task based camera asset (FREE)

xDGameStudios

GameMaker Staff
GameMaker Dev.
[LINKS]

xCamera (marketplace)

xCamera (itch.io)

[DEMO GIF]



[INFORMATION]
This is a task based & modular 2D Camera controlling 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 (or through code with this example):
GML:
var _w = 800, _h = 600;
surface_resize(application_surface, _w, _h);
window_set_size(_w, _h);

var _guiFactor = 1;        // The factor applied to the gui layer
var _sizeFactor = .5;    // The factor applied to the camera (zoom = x1)

display_set_gui_size(_w*_guiFactor, _h*_guiFactor);
view_wport[0] = _w * _sizeFactor;    // this is the be the equivalent of x1 camera zoom
view_hport[0] = _h * _sizeFactor;    // this is the be the equivalent of x1 camera zoom
After that you just need to call the camera constructor with the given view and that's it (see the example code just below)
GML:
camera = new Camera(0, 0, 0); // This will create a camera(x, y, view) at position (0, 0) attached to view 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.
The camera can be stored inside a persistent 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.
  • follow: follows an instance or object type [instance]
  • focus: focus on a point [x, y]
  • lock: locks movement for given axis [horizontal, vertical]
  • zoom: zooms the camera by x amount compared to the view size (*) [targetZoom, duration, callback]
  • limit: limits the camera placement to a region [x1, y1, x2, y2]
  • shake: shakes the camera (*) [strength, 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):

GML:
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:
GML:
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
  • cm_lerp: lerps between the current and next point (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: move using a smooth ease in-out algorithm (0 - max, higher is smoother), 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.

[CHANGE LOG]
v1.0.1
Initial release (marketplace failed on me)
v1.0.2 Update the demo project to be android (touch) ready

[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.
 
Last edited:

Sudo

Member
This and all my other assets should now be free!
Thank you all and hope you enjoy!
Great asset! Can this camera follow more than one object? Like say if players move away from each other it zooms out to keep them in view, or zooms in when they are near?
 

MCHLV

Member
Hello,

Thank you for this. This is a great engine. Robust and allows some customization too.
Just something I am missing... what instructions should I run when changing room. Is there something like a camera_init ?
Creating camera in room 1 and going to 2 is not working on my side (camera setting from room 1 are not applied, calling follow does nothing for instance..).
Thanks for your help


M.
 
Top