Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a light type of entity for lighting effects #267

Open
eonarheim opened this issue Apr 22, 2014 · 4 comments
Open

Add a light type of entity for lighting effects #267

eonarheim opened this issue Apr 22, 2014 · 4 comments
Labels
feature Label applied to new feature requests stale This issue or PR has not had any activity recently

Comments

@eonarheim
Copy link
Member

eonarheim commented Apr 22, 2014

Context

It would be useful to have the ability to utilize dynamic lighting effects.

Proposal

Something like this

// x, y, radius, luminosity
var light = new ex.Light(100, 100, 10, 1);
game.currentScene.addLight(light);
@eonarheim eonarheim added this to the 0.4 Release milestone Apr 22, 2014
@jedeen jedeen modified the milestones: 0.4 Release, 0.5 Release Sep 30, 2014
@jedeen jedeen added the feature Label applied to new feature requests label Apr 30, 2015
@jedeen jedeen modified the milestones: 0.6 Release, 0.7 Release May 10, 2015
@jedeen jedeen modified the milestones: 0.7 Release, vNext May 26, 2015
@jedeen
Copy link
Member

jedeen commented Sep 12, 2017

This might be worth looking at: https://github.com/gre/illuminated.js

@github-actions
Copy link

github-actions bot commented Jul 4, 2021

This issue hasn't had any recent activity lately and is being marked as stale automatically.

@github-actions github-actions bot added the stale This issue or PR has not had any activity recently label Jul 4, 2021
@luttje
Copy link

luttje commented Jan 31, 2022

I hope you don't mind me bumping this old issue, but I'm looking for something like this. In the meantime while we wait I've got something that may help others looking to light their scenes.

I've conjured up a very cheap way to fake lighting:
image

This is the general process:

  1. Overlay the game canvas with another canvas (#lightingCanvas), match the game canvas size and position
  2. Paint the whole #lightingCanvas translucently black (this mimics darkness)
  3. Ask all objects which type of 'light mask' they emit and where. Example mask:
    spot
  4. Using globalCompositeOperation = 'destination-out' cut out the lit part from the darkness on the #lightingCanvas

Objects can register their lighting in their constructor like this:

const lightSprite = Resources.light_Spot.toSprite();
LightingManager.instance.on(LightingEventTypes.RegisteringLights, (ev) => {
  // This event handler is called everytime lighting is updated

  // Let this big light be drawn:
  ev.lightingManager.registerLight(
    new GraphicLightEmitter({
      pos: this.pos,
      graphic: lightSprite,
      scale: vec(5, 5)
    })
  );
});

I quickly made a little demo based on the platformer demo and it's custom-loader.ts shows how to light the whole screen on loading.

Of course it isn't realistic lighting at all, but for some style of pixel art it may just be enough.

I hope this helps someone.

@eonarheim
Copy link
Member Author

@luttje Wow this is very cool!

@eonarheim eonarheim removed this from the vNext milestone May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Label applied to new feature requests stale This issue or PR has not had any activity recently
Projects
None yet
Development

No branches or pull requests

3 participants