How to use overlays?

Started by jumpjack, Mon 26/12/2022 15:49:32

Previous topic - Next topic

jumpjack

Documentation on overlays say that this line:

Code: ags
Overlay* myOverlay = Overlay.CreateGraphical(100, 100, 300);

Should show sprite slot 400 at position 100,100 of the screnen... but I don't see anything.

To see something, I have to add:

Code: ags
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawImage(roomX - tilewidth/2, roomY-tileheight*4/2, myOverlay.Graphic);

Same happens for everything else: Overlay.CreateRoomGraphical, Overlay.CreateRoomTextual, Overlay.CreateTextual,...

I can't find any other example on overlays, can anybody help?

But actually I don't know if I need overlays for my purposes: I want to build a room tile by tile, and some tiles have transparent pixels, so the player should be visible when it pass behind such tiles.

Maybe I should use objects instead? Or something else?

Or should I create my own walkbehind image programmatically? I have available two versions for each tile image: one single PNG with some transparent pixels, or a BMP couple (image + transparency mask).


Crimson Wizard

#1
The documentation for Overlay.CreateGraphical also sais this:
Quoteif the Overlay variable goes out of scope, the overlay will be removed. Hence, if you want the overlay to last on-screen outside of the script function where it was created, the Overlay* variable declaration needs to be at the top of the script and outside any script functions.

If you want overlay to remain after the function is finished, you need a global variable (declared outside of the function).
The creation of overlay remains inside a function (as AGS script does not support calling functions in the global scope).

For example:
Code: ags
Overlay *myOverlay;

function Room_AfterFadeIn()
{
    myOverlay = Overlay.CreateGraphical(100, 100, 300);
}

jumpjack

Thanks, now it works.

What about the other questions? My player is currently walking over everything...

Crimson Wizard

#3
So, room background is always behind everything, so whatever you draw there will always be behind.

Characters, room objects and walk-behinds have Baseline property, that determines their sorting on screen. By default character's and object's baseline is automatically bound to their Y position. Setting Baseline to any custom value will override it, and let you sort these objects differently.

Since AGS 3.6.0 Overlays use ZOrder property, but that's essentially the same (it was called to match the GUI's property of same name). If you create overlays on the room layer, their ZOrder will sort among other room elements' baselines.

EDIT: Oh, right, Overlays have their ZOrder set to some very low negative value by default, this is for backwards compatibility with older versions of AGS, where they were always drawn behind GUIs. Possibly this was a design mistake to keep exact behavior for room overlays, but it is like that right now.

EDIT2: So, if you like to have Overlays sorted by the same rule as Characters and Room Objects, you need to set their ZOrder to their bottom Y position.

jumpjack

My character apparently has .z and .Baseline values constantly = 0 while it moves around the room (I put their values into a label in global script, together with x and y). Should I enable anything to get them updated?

Additionally, "z" looks more like a "real world" value rather than an "engine value", as if I manually increment .z, the character raises, but if I increment .Baseline, character does not move, but it gets drawn behind some objects with different baslines...


Crimson Wizard

Quote from: jumpjack on Mon 26/12/2022 16:52:44My character apparently has .z and .Baseline values constantly = 0 while it moves around the room (I put their values into a label in global script, together with x and y). Should I enable anything to get them updated?

Additionally, "z" looks more like a "real world" value rather than an "engine value", as if I manually increment .z, the character raises, but if I increment .Baseline, character does not move, but it gets drawn behind some objects with different baslines...

When Baseline reports 0 that means that Character's Y is used instead. If you set Baseline to something besides 0 that would use that fixed value regardless of character's location.
https://adventuregamestudio.github.io/ags-manual/Character.html#characterbaseline

Character's "z" is a special graphical offset by Y axis, which does not affect sorting at all. It's mostly a historical feature, used to simulate "levitating" while keeping same y position in the room.
https://adventuregamestudio.github.io/ags-manual/Character.html#characterz

SMF spam blocked by CleanTalk