rot.js icon indicating copy to clipboard operation
rot.js copied to clipboard

Updating the position of a light

Open Cleptomania opened this issue 8 years ago • 2 comments

Suppose I want a light that follows the player, something like a torch. Obviously this needs to update as the player moves.

I initially accomplished this by using the clearLights() function every time the game updates, then creating a new light at the player's position, and lastly calling compute().

This works fine and dandy, however let's say I have many different lights throughout the game, some of which are static and non moving, others dynamic like the player's torch. Is there any more effective system than keeping a list of all lights and clearing them and then re-adding every game update?

I feel that if this support isn't already there(I may just not be seeing a way to do it that's already there), it could easily be added to the ROT.Lighting class.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/36493450-updating-the-position-of-a-light?utm_campaign=plugin&utm_content=tracker%2F297828&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F297828&utm_medium=issues&utm_source=github).

Cleptomania avatar Jul 26 '16 03:07 Cleptomania

Hi @Cleptomania,

the current API has no dedicated method for moving, that is correct.

The idea behind this design decision is that to actually move a light, you need to identify it somehow -- preferrably via its coordinates (as having multiple lights in one place is not tested, not expected and will probably yield strange/buggy results). But once you have your (old) coordinates, moving a light source boils down to

setLight(oldX, oldY, null);
setLight(newX, newY, myLightColor);

...and I thought that having a wrapper method for these two lines is superfluous.

What do you think?

ondras avatar Jul 30 '16 16:07 ondras

Yeah that makes sense. I didn't think about doing it that way. I've made a Light class within my game that tracks the positions of a light and handles updating it and that seems to work well. Within my map I can just contain an array of all my Light objects and update the needed lights.

Cleptomania avatar Jul 31 '16 08:07 Cleptomania