Eye - Grisgram/gml-raptor GitHub Wiki

The Eye can help you with many camera actions in your game, including parallax scrolling and following ("looking at") a specific object in the game all the time.

Let's start with the variable definitions:

image

As you can see in the picture above, the Eye is also a Saveable object, so your runtime values will be part of the save game.

New variables:

Variable Description
camera_index The camera to use
stop_at_room_borders If true (the default), the Eye will automatically stop moving an axis that reaches the room borders
parallax_enabled Enable this, if you have multiple layers that shall scroll at different speeds when the camera moves
parallax_layers A string array containing the layer names that shall scroll
parallax_factors A real number array that holds the speed multipliers for movement of each of the scrolling layers.
The values will be matched by their index with the parallax_layers. This means, the first value is the multiplier of the first layer in the parallax_layers array, the second one is for the second layer and so forth

Important

The Eye can only act in a room, where Viewports & Cameras are activated!

A real example

Let's look at this with a real example from a demonstration game:
parallax-scrolling

Look closely at the background of the scene. Can you see, that the clouds and the trees are moving in a different speed than the world in the foreground? That's parallax scrolling!
It adds an illusion-of-depth to your scene and can spice up almost any moving world.

This demonstration has been created with an Eye, that had these settings: image

The room had four background layers ("bg0"..."bg3"), those were entered in the parallax_layers array.
The multipliers for those layers were 0.2, 0.4, 0.6 and 0.8.
You can read them as percentage ranging from 0..1, where 1.0 means 100%.
So, the backmost layer, the clouds, moved with 20% of the scroll speed and the trees with 40%, 60% and 80%.

The Eye can do even more

Aside of the powerful parallax scrolling effect, the Eye also offers functions to follow an object in the scene. GameMaker has this option also built-in. When you set up your viewport and camera, there's an Object Following setting you can set at design time and even at runtime.

Why should you still pick the Eye over the built-in function? Because the built-in function...

  • ...has no clear control, when the camera follows an object, whether it will stop at the room borders or not
  • ...does not support code- and painless parallax scrolling
  • ...you have to clear and reapply a followed object, while you can easily set_enabled on an eye to temporary stop following

Make the Eye follow an object in the scene

It is as simple as invoking this one function:

/// @function		attach_to(_instance)
/// @description	Attach the eye to an object (or noone).
///			As long as the eye is attached, the eye (and so the camera)
///			will follow the attached object, keeping it in the center of the screen.

Camera control

You can switch the active camera of the Eye any time with

/// @function	set_camera_index(_index)

and you can query the currently controlled camera through

/// @function	get_camera_index()

That's all you need for the Eye. A very simple, but also very powerful object.

⚠️ **GitHub.com Fallback** ⚠️