Background Lighting Script

Started by Akumayo, Tue 18/10/2005 03:13:58

Previous topic - Next topic

Akumayo

This is a nifty little script I use to light my backgrounds.Ã,  I thought I'd share.Ã,  It turns the WHOLE background to a certain lighting, as opposed to regions which do characters/objects only.Ã,  It's usefull for making a room dark before the player hits a lightswitch and such.

-Create a sprite the dimensions of your rooms and the color you want to tint the room (usually black for dark or white for light)
-Set View to this sprite and create a character, we'll call him TINT, he has the said view.Ã,  Place him at x=160, y=200

In the beginning of the script (before game_start function):
Code: ags

function TintLevel(int tint) {Ã,  //From 0, a totally lit room, to 100, a pitch black room
Ã,  character[TINT].Transparency = (100-(tint));
}


Then, if you want to change the lighting in a particular room, let's say you need to turn on a light.Ã,  In the room's startup script, call:
Code: ags

TintLevel(70);

Then, for the interaction of the character flicking the switch, call:
Code: ags

TintLevel(0);


If you want the tinting to be in EVERY room, useful for things like a steadily darker night, and a dungeon or cave.Ã,  This assumes EGO is your playable character.Ã,  InÃ,  repeatedly_excecute:
Code: ags

character[TINT].ChangeRoom((character[EGO].Room),Ã,  160,Ã,  200);
"Power is not a means - it is an end."

Pumaman

Thanks for sharing :)

However, it's worth pointing out that using a full-screen-sized transparent character can be rather slow, especially if your game is high-resolution.

GarageGothic

Also, there are other - possibly better - ways of achieving the same effect. If you're using a uniformly colored sprite you might as well use a full-screen GUI. That would also allow you to change it's color on-the-fly, not only changing between different levels of transparency but also between different tints.

Secondly, to put the Character[TINT].ChangeRoom code in repeatedly_execute is unnecessary. It would be less messy to call it in on_event for eEventEnterRoomBeforeFadein.

Akumayo

Hrm...A GUI would be a lot better wouldn't it?  Anyway, I use a solid black character in Labyrinth to simulate growing darkness, and my game doesn't slow down much at all.  I'm running fullscreen with 640x400 resolution too.
"Power is not a means - it is an end."

fovmester

Nice!! I was thinking of putting something like this in my game. Using a GUI like this seems like a good idea. Might want to put in an option to turn the effect off, though (for those with low-end computers).

Akumayo

Yeah, I'll bet that'd be realatively easy, you could just ask the player, and if they wanted it off you could place a
Code: ags

character[TINT].ChangeRoom(-1);
"Power is not a means - it is an end."

SMF spam blocked by CleanTalk