Tutorial0 - Lights | Basics

Getting started

Now, you may have the base engine with all the sprites, objects and room to run TLighting.

Creating a basic light

First of all, we need to add new object. We call it obj_light for convenience. Set a sprite for your obj_light (e.g. spr_light, that i put in this example).

Now, in this object, we must add this code in some events.

Create Event

We must add the following function to set up a light.
tl_light_create(Mask Sprite, x, y, color);
In this way
tl_light_create(spr_light_circle, x, y, c_white);
You can use the SpriteMask, Color, Coordinates what you want
Now, put some light in room_game and run the game.

Creating a static light

- To set your light Static (you cannot move them during the game) for increase the framerate

Create Event

my_light = tl_light_create(spr_light_circle, x, y, c_white); tl_light_static(my_light, true);
In this way you have set the light as static, and the engine don't calculate it every steps. TLighting, stores the light mask in the RAM of your computer until you shut down the game.

Setting the quality of a light

- To set the quality of your light

Create Event

my_light = tl_light_create(spr_light_circle, x, y, c_white); tl_light_quality(my_light, 0.7);
The light quality is the scale amount to apply at the light surface. This value can be from 0 to 1 (e.g. 0.2 , 0.5, 1, 0 , etc.) With this function you can speed up your game, becouse GameMaker has to render lesser pixel.
(a 1000x1000 surface has 4x pixels then a 500x500 surface, then a 0.5 scale, increases your fps)

Move and rotate your light

- To rotate your light

Create Event

my_light = tl_light_create(spr_light_circle, x, y, c_white);

Into an Event

tl_light_rotate(my_light,200);
you can rotate your light by an angle from 0 to 360 degrees.
- To move your light

Create Event

my_light = tl_light_create(spr_light_circle, x, y, c_white);

Into an Event

tl_light_move(my_light, 320, 123);
you move around your light in the room with this function

Free the memory

- To delete your light

Into an Event

tl_light_delete(my_light);
This function deletes the light surface and destroys all data structures.

Activate and Deactivate your light

- When you want to deactivate your light you can use this function

Into an Event

tl_light_active(my_light, true or false);
if you set true, your light will be active, else if you set false, the engine don't calculates and render this light.

Get the status of a light

- Use "get" functions

Into an Event

tl_light_get_color(my_light); tl_light_get_sprite(my_light); tl_light_get_xscale(my_light); tl_light_get_...
With these functions, you can retrive informations about lights. you can find the description of each function in the left column of this site.