/LightingSystem2D

Lightweight lighting engine for GameMaker Studio 2

Primary LanguageYaccMIT LicenseMIT

Lighting System 2D for GMS 2.3+ | v1.0.0

@babaganosch


Lighting System 2D is a lightweight light engine for GameMaker Studio 2.3+. It's extremly simple to setup and easy to use. This engine is based on the prettylight engine by @niksudan

This repository contains a demo project showcasing a simple implementation, but you only need the 'LightingSystem' script, and the Gaussian Blur shaders in a real implementation.

Installation

  • Copy the LightingSystem script into your project.
  • Copy the shd_gaussian_horizontal shader into your project.
  • Copy the shd_gaussian_vertical shader into your project.

TODO

Fix this README. A lot of information is missing

Usage

  • Call UpdateLights() In the end step event of a controller object
  • Call DrawLights() In the end draw event of a controller object

In order to create a new light source, call the LightSource(sprite, attributes) constructor. For example:

light = new LightSource( spr_light, {
  color: c_orange, 
  alpha: 0.7, 
  flicker: { 
    amplitude: 0.05, 
    speed: 0.02 
  }
});

The light source needs a sprite when constructed. It is possible to create simple circular faded light sprites, runtime, by calling the ConstructLightSprite(size) function, which will return a sprite asset of given size in diameter.

spr_light = ConstructLightSprite(128);

Don't forget to free the memory related to the light source when it is not needed any more

light.free();

System methods (todo: add descriptions)

SetLightAmbient(color, brightness);
SetLightBlurring(strength);
GetLightBlurring();
DrawLights();
UpdateLights(frame_delta);
CleanupLightSystem(active_only);

Light source methods (todo: add descriptions)

.free();
.activate();
.deactivate();
.get_active();
.set_active(value);
.get_flicker();
.set_flicker(params);
.move(dx, dy);
.set_offset(x, y);
.set_color_ext(color, alpha);
.set_color(color);
.set_alpha(alpha);
.set_scale(scale);
.set_size(size);
.get_offset();
.get_color();
.get_alpha();
.get_scale();

Credits

  • niksudan - Author of prettylight, which this engine is based upon
  • xygthop3 - The gaussian blur shader