GameMaker (2.3)
Icon

xCamera

xDGameStudios

You must be logged in to obtain assets

Description

[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)

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.

  • 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):

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

  • 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.

[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.

End User Licence Agreement (EULA).

Age Rating: 4+

Version

GMS2.3 - Version 1.0.2. Published May 6, 2021

Reworked the demo project for enhanced compatibility across platforms.

Loading, please wait

Package contents

Loading, please wait

What is the issue?

Loading, please wait