# Dynamical recoloring of tiles

**URL:** <https://discourse.libsdl.org/t/dynamical-recoloring-of-tiles/10628>\
**Category:** SDL Development\
**Created:** [May 4, 2004, 3:20pm UTC](https://discourse.libsdl.org/t/dynamical-recoloring-of-tiles/10628 "2004-05-04T15:20:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kornel\_Kisieleiwcz](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/f475e1/32.png) [@Kornel\_Kisieleiwcz](https://discourse.libsdl.org/u/Kornel_Kisieleiwcz)\
**Post date:** [May 4, 2004, 3:20pm UTC](https://discourse.libsdl.org/t/dynamical-recoloring-of-tiles/10628/1 "2004-05-04T15:20:38Z")

</div>

Hello again,

In the isometric engine I’m working on I want to have a simple degree  
of something like dynamical lightning - that is darkening the tiles  
used depending on the distance from the lightsource. What would be  
the best approach in SDL to do that? I thought about making new  
instances of the given tile on the fly and modyfing each of their  
pixels. Is there a better way to handle that?

regards,  
Kornel Kisielewicz

---

<div class="post-metadata">

**Author:** ![Aaron\_Sullivan](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/aaron_sullivan/32/238_2.png) [@Aaron\_Sullivan](https://discourse.libsdl.org/u/Aaron_Sullivan)\
**Post date:** [May 4, 2004, 3:46pm UTC](https://discourse.libsdl.org/t/dynamical-recoloring-of-tiles/10628/2 "2004-05-04T15:46:51Z")

</div>

Of course using an alpha channel would make this very easy.  
Just laying down a black tile with varying alpha levels to make  
it darker. After working with OpenGL in 2D for awhile now,  
I don’t know how I’d go back. Using alpha with OpenGL in 2D  
costs almost nothing in performance.

Without OpenGL I would pre-process all of your tiles, not “on  
the fly” as you say but before the action in your game takes place.  
Also, only a few shades like bright, normal, dark, black. You’ll  
still get a pretty good effect and that’s only 4 times as much  
memory. 😉

If you try to modify the pixels each time you draw a tile you are  
looking at major slowdown.

You’ll find this is true with any approach, not just SDL.  
So, unless this turns to actual implementation examples, it’s  
probably a bit off topic.

---

<div class="post-metadata">

**Author:** ![Kornel\_Kisieleiwcz](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/k/f475e1/32.png) [@Kornel\_Kisieleiwcz](https://discourse.libsdl.org/u/Kornel_Kisieleiwcz)\
**Post date:** [May 4, 2004, 6:06pm UTC](https://discourse.libsdl.org/t/dynamical-recoloring-of-tiles/10628/3 "2004-05-04T18:06:02Z")

</div>

Hello again,

In the isometric engine I’m working on I want to have a simple degree of  
something like dynamical lightning - that is darkening the tiles used  
depending on the distance from the lightsource. What would be the best  
approach in SDL to do that? I thought about making new instances of the  
given tile on the fly and modyfing each of their pixels. Is there a better  
way to handle that?

regards,  
Kornel Kisielewicz

---

<div class="post-metadata">

**Author:** ![Stephane\_Marchesin](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@Stephane\_Marchesin](https://discourse.libsdl.org/u/Stephane_Marchesin)\
**Post date:** [May 12, 2004, 6:28pm UTC](https://discourse.libsdl.org/t/dynamical-recoloring-of-tiles/10628/4 "2004-05-12T18:28:07Z")

</div>

Kornel Kisieleiwcz wrote:

> Hello again,
> 
> In the isometric engine I’m working on I want to have a simple degree of  
> something like dynamical lightning - that is darkening the tiles used  
> depending on the distance from the lightsource. What would be the best  
> approach in SDL to do that? I thought about making new instances of the  
> given tile on the fly and modyfing each of their pixels. Is there a better  
> way to handle that?

You could draw a black transparent rectangle on top of each tile to  
darken it. Using different alpha values, you might achieve the desired  
result.  
However, that’ll be slower because alpha is expensive.

Stephane
