I have been thinking about something: an easy way to apply simple lighting to games. I was thinking about creating an emtpy ImageData, and filling it with a dark color, with a low alpha value. And loop through all of the tiles, and measure the distance from every light source, and then apply the correct shading.
Measuring distances is pretty easy:
d = sqrt( (x2 - x1) ^ 2 + (y2 - y1) ^ 2 )
And then I would use ImageData:setPixel() to apply appropriate shading to the tile/pixel.
I was wondering if this would be too slow, and if there were any alternatives. I do not really want to get into PixelEffects, as I only need very simple lighting.
Lighting
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Lighting
I've seen several ways of adding light to a game. Have you tried searching through the forums?
When I write def I mean function.
Re: Lighting
What's wrong to just use a simple shader?
Just an option depending on what you want to accomplish.
Just an option depending on what you want to accomplish.
- Attachments
-
- spotlight.love
- Pixel effect spotlight
- (204.82 KiB) Downloaded 301 times
Re: Lighting
That is not the effect I wanted, but thanks anyways. I don't want it to be a perfect circle, but rather be "blocky", and only have one shade per tile.
Re: Lighting
Sounds like you want a flood fill algorithm that traverses out a number of tiles from the light source, remembering distance traveled, and setting the lighting value to the larger of the various lighting sources that traveled the block. This would give you a kind of diamond lighting shape, but making it a circle would be easy enough if you took some considerations like if you travel to the same block from multiple directions, add a logarithmic value.
Re: Lighting
I second his opinion, off course there are many ways of doing it. Search through forums /blogs else I'll tell you ways.I've seen several ways of adding light to a game. Have you tried searching through the forums?
Re: Lighting
I'd like to create SuperMeatBoy like lighting but there is no point using shaders (that my current pc cannot run) when SuperMeatBoy doesn't use much of them (which my current pc can run)
Lua is not an acronym.
Re: Lighting
It doesn't have to be slow, if you save your rendering to a Canvas, you only need to calculate the lighting once. But if you want stuff to react to movements of the light source for example, it might get very slow. It is also very resolution dependent. If you calculate the lighting in a low resolution and then scale it up, it can be much faster (and look more pixely which is awesome).
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- substitute541
- Party member
- Posts: 484
- Joined: Fri Aug 24, 2012 9:04 am
- Location: Southern Leyte, Visayas, Philippines
- Contact:
Re: Lighting
There are lots of ways. Probably the simplest isto find the distance from one tile, to a light source, divide it by something to create a ratio, multiply the ratio by its brightness (which is a percentage) and just use the new value to somehow darken the tile.
Currently designing themes for WordPress.
Sometimes lurks around the forum.
Sometimes lurks around the forum.
Who is online
Users browsing this forum: Nikki and 4 guests