Region lighting

Started by Virgil, Tue 22/09/2009 15:00:01

Previous topic - Next topic

Virgil

I've checked through the manual and script index for the game, as well as a few topics on the forums, and for the life of me, I cannot get region lighting to work. I set the lighting variable for the region, but it doesn't seem to have any affect on objects or characters in the region. When I try to script the light level in, it always returns as an error.

I know this is a simple concept, but for some reason I can't grasp it. Thanks for any help.

For reference, when I script:

Code: ags
region[1].LightLevel = 20;

Khris

I tested this using the Roger character. I can't get him to become lighter, but if I enter something below 100 in the room editor, he gets darker.

In script, the most important thing is to put the command inside a function. You can't just put it in the room script directly.
Create the function for the room's "player enters screen before fadein event", then put the command inside.
Note that in script, proper values are -100 to 100, unlike in the editor, where it's 0-200.

Virgil

Hm.. okay, thanks, but it still isn't working. I tried putting in negative numbers into the region panel, and putting in LightLevel in the room_Load and room_AfterFadeIn, and none seem to work. I am still using the Roger sprites, if that makes any difference..

tzachs

There's a property for the character: UseAreaLighting (you can find it in the designer, double click on the character).
Is it set to true?

Virgil

Yes, I checked before I posted here. When I tried (and failed) with the object, it was also set to use area lighting as well.

Khris

I'm not sure if lighting works properly if the game is set to 256 colors.
If you're using 16bit or 32bit, did you link the functions properly?
If you're unsure, put a Display call in AfterFadein.

Virgil

What do you mean by linking the functions? I think that may be the problem. But if I just set it in the region without setting it in the script, shouldn't it automatically work?

Thanks for all your help.

Khris

Let's do some debugging:

Add this to your room script:

Code: ags
function on_key_press(int k) {
  if (k == 32) {
    Region*re = Region.GetAtRoomXY(player.x, player.y);
    Display("Light level at player's position: %d", re.LightLevel);
  }
}


Run the game, move the player onto the region, then press space.
What does it say?

Linking the function means that in the room's event pane (lightning bolt icon), next to "Enters room after fade-in", it says "room_AfterFadeIn" and that that's exactly the name of the function you've put the script command into.

Virgil

Okay, when I press space in the regions, it gives me 'light level at -20' and further, since I tested a few regions. But it doesn't seem to affect the EGO character moving around.

Ah, so, in linking a function, you paste the Light Level script in the box next to 'enters room after fade-in'? Or in the script itself?

Thanks for your help.

Oh, another quick thing. When I open up the game to test it, the screen stays black until I press a key or mouse button. What's causing this?

Khris

After selecting an event by clicking its name, a little ellipses button appears in the empty field. If you click that, the function is created in the appropriate script and linked to automatically. (This is explained in part 3 of the tutorial, btw).
Then the script is opened and the cursor is usually placed at the newly created function.
To put it another way, if you just paste a function called "room_AfterFadein" into your room script, it will never get called until you enter that name in the field.

QuoteWhen I open up the game to test it, the screen stays black until I press a key or mouse button. What's causing this?
Looks like you put a Display call in room_Load. At that point, before the first room is loaded, the screen stays black but the game nevertheless waits for a click.

So, what is your game's color depth? Does it work if you create your own character? Try setting the light level to 20 in the editor / -80 in the script.
Like I said, Roger got noticeably darker when I set the light level to -50.

Virgil

Ah, okay, yeah I understand how to use the ellipses and everything, but didn't know you couldn't paste in code. Not that I was, but okay.

I do have a display call, but its in AfterFadeIn, and I don't even have room_Load being affected. I've taken out that display call, and still nothing. But I will keep playing around with it. 

My color depth is a 16, and I've tried it with other default sprites (like the inventory buttons), with no difference. But it did work with another sprite. Excellent.. wow, this whole deal with Roger has given me a lot of trouble. Thanks for all your help Khris.

HyperAnimated

Don't want to hijack the thread, but I'm having a similar problem...

My game is set to 32 bit, my char. sprite is 24 bit with an alpha channel, UseRoomAreaLighting is set to true...but I still can't get the lighting region to work.

It can make the character darker, for any value below 100 in the editor.  But it won't make him brighter over 100.  I'm trying for a walking-under-a-streetlamp effect, and the best I can do so far is make the whole room a darker region at 80, and no LightLevel region under the lamp, so he looks brighter.

Any ideas?  Thanks!

Khris

From the manual:

NOTE: Light levels only work when the character's graphic is at the same colour depth as the background (ie. a 256-colour character in a hi-colour game won't get lightened).

Try saving the background as a 24bit image, too.

HyperAnimated

Hmm...I'm still kind of new to Illustrator CS4, does anyone here know how to export PNGs as 24 bit without losing antialiased edges?

I tried reducing it to 24 bit in PSP7, and it really screwed up the background textures and made any gradients go all blocky.

Matti

#14
I'm almost exclusively using Illustrator (CS3) and I'm only exporting sprites with alpha-channels. But what exactly is your problem?

When I export png-images with transparency, they're always saved as 24-bit and they always work in a 32-bit AGS game..

HyperAnimated

Well, I'm exporting both my background and my character sprite from CS4 as PNGs with anti-aliasing and transparent backgrounds.  And my game is set to 32 bit.  But for some reason the LightLevel control still won't brighten my character, only darken him.  If I set the LightLevel value from 100 - 200 in the editor menu, he stays exactly the same.  But if I go below 100, he'll darken appropriately.

Also, side question - do you have any idea why Illustrator cuts off the very bottom edge of my sprite when I export it?  If I don't export the entire artboard and let AGS crop the sprites, Illustrator clips the last few pixels of his feet.

Thanks again!

Matti

Ah, I never used lighting levels above 100% (and it doesn't look very good as far as I know). Will test it soon.

Regarding your other question: Yeah, I was always wondering why Illustrator does that*, and after going through some forums it seems that there's no way around that. But you can just copy your character into a newly opened File with the right size and "save for web and devices" - which is, I think, copying the entire artboard. Just make sure that the artboard has the right size.

* it's not always the bottom edge.. it can be every edge.

SMF spam blocked by CleanTalk