day/night, lighting

Anyone know how to take a pixel and make it look shaded or darker? If a character walks under a tree I’d like to shade his sprite, or when nighttime comes make it look dark all-around (including the background for that matter). Older games seemed to slowly apply some kinda blue to darker blue on the pixels for this. I’ve been looking around for something for a bit and I haven’t found anything that really seems to apply.

I think there are some methods:
If you want the sprite to be darkened globally:

  • if you are using paletized sprites, simply change the palette. :slight_smile:
  • if you are using true color sprites, you can:
    • use an other bank of sprites, showing the other colors (memory expensive)
    • apply a blue transparent mask over the sprite ( cpu and memory expensive)

if you want it to be partially darkened when coming into shadow, the only solution i think of is using shadow masks.

Well that was fast. :stuck_out_tongue:

I’ve never dealt with any palette stuff, I understand how they work kinda, just not when it comes to using them in games. Day/night wouldn’t happen automatically so I would need to generate a bunch of different blue’ish crap, I’m not sure how that would even be done. Would you end up doing that by hand? I haven’t a clue really.

Using separate sprites is not an option in this case.

Applying a blue transparency… I haven’t done that either but it sounds easier, but I’ve heard it’s dog-ass slow since you can’t get that to be hardware accelerated? I’m working off extremely fragmented memory/pices of things I’ve read so I could be horribly misinformed.

I’ll look into it…

Edit: ok I peeked around… I’ll end up having to make some BufferedImage’s with the blue’s and the alpha level set and just draw that over the entire screen, Correct?

As far as shading sprites I think that sprites will have to have a BufferedImage just to handle that per frame, figure out which pixels are being drawn and give then some sorta grey/black alpha and set the rest to transparent and then drawing that over the portion of the screen where the sprite is, I’m assuming thats possible. =P

The game acually needs to be able to draw/not draw specific pixels of sprites/areas of the game, and it varies per frame. So it complicates the alpha portion a bit more I think. The main backbuffer I’m using a memory image source type deal where I can just change the pixels and update. I may change that to support having an alpha option for the other graphics in the game, but who knows.

ok NOW I’m tired and rambling, thanks for the help, I think I have a bit more direction then I did before. Time to experiment. Goodnight. =)