PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

optimal way to simulate day/night cycles?

I am making a tilebased game that will simulate realtime day/night cycles.

I try to achieve a darkness effect by alphablitting a completely black image (240x320px) on top of the backbuffer just before flipping.
This has a huge effect on performance however! Framerate goes down from 50fps to 20fps.

Obviously this isn't acceptable so I'm looking for other ideas to solve this problem of simulating day/night.
Change the backlight brightness.
Use the colorize blit effect.
why dont you darken you tile set?

That would only have to be done once, so it wouldn't affect performance at all.
Change the backlight brightness.


:D

Actually, you should really pre-render all your tilesets. If you have one large surface with all your tiles you can simply create copies of that in memory and FillRect with opacity on top of that. If you have too many tiles you might consider grouping them into areas of your game and loading / unloading when the player moves around.
Hi!

Playing with GD's colorize effect and adjusting the original image's colors worked for me. You have to experiment a lot though.

- Erick
I considered prerendering all my tilesets but then the colorkey for transparancy would become messed up.
Maybe I should change the sourcekey each time a prerender my tiles with a different opacity?
You could use BLTFAST_COLORIZE as suggested and also use the COLORKEY flag. Then only your tile data would get affected, not the color key data.

So.. You could create a new surface (same size), fill it with the color key, and then BltFast with the COLORIZE and COLORKEY flags to it...
Anonymous wrote:I am making a tilebased game that will simulate realtime day/night cycles.

I try to achieve a darkness effect by alphablitting a completely black image (240x320px) on top of the backbuffer just before flipping.
This has a huge effect on performance however! Framerate goes down from 50fps to 20fps.

Obviously this isn't acceptable so I'm looking for other ideas to solve this problem of simulating day/night.


The method you use is really going to depend on what style of game it is. If you're going to be building a simple 'flat' platformer, you should probably just prerender each sprite. If they cast shadows based on the light source position, you'll also need to cast the shadow and 'shift' it left/right/up/down depending that position. If you have a heightfield terrain engine, you may want to cast a ray from the lightsource and darken terrain pixels that aren't touched by the ray to simulate terrain shadows.

Obviously this is much easier if you only have two lighting phases - day and night - and becomes more difficult if you actually want a moving light source. But remember it doesn't have to be perfect... it just has to be good enough to give the impression that night/day cycles are actually happening.
Johan, I gave COLORIZE a shot and I am amazed how fast it is. I can in fact do it in realtime (ie. no prerendering) without much of an fps drop.