Activating/Deacticating overlapping walkbehinds depending on walkable area

Started by TheEyess, Fri 13/10/2023 15:51:24

Previous topic - Next topic

TheEyess

Hey,

I am facing the following problem: I have a scene in a prison with one "cage" stacket on top of each other. The player char will be in the lower cage, an NPC in the upper one. I have thus created one walkable area for each cage and one set of walkbehinds (for the iron bars) for each cage. Since the two cages are stacked on each other, the walkbehinds are overlapping which breaks my room :(

I am now wondering if there is a way to link walkbehind no. 1 to walkable area 1, so that only characters on walkable area 1 will be affected by walkbehind 1, and only that.

Thank you in advance, I haven't been able to find an answer since now.

Khris

You cannot do that (linking a wb to a specific wa). Also, wbs cannot overlap.

A screenshot would help massively to solve this, but for now you can maybe solve this by using non-clickable objects instead?

You can also change the order in which characters/objects are drawn by AGS by setting baselines to specific values. Both characters and objects have a baseline property, and by manually setting them to suitable y-coordinates, you can specify exactly how the four things cover each other.
Simply setting the NPC's baseline and their bars' baseline to a value high enough should move them in front of the bottom cage.

Edit:


The sprites I used:


I picked a coordinate a few pixels below the bottom cage (205) and used that for the baseline of the left sprite's object, then set the hologram's baseline to 206 and the right sprite's object's to 207.

TheEyess

#2
Hey Khris,

thanks so much for your help! I somehow didn't now about character baselines before.
Your solution is working fine for the cages themselves and the player character in the lower one, but I seem to be missing something for the NPC in the upper one. It is correctly covered by the upper cage's bars but is also hidden behind the upper cage's floor (which is part of the sprite for the lower cage, as shown in your post).  I can't get it to overlap the cage floor... Here are the settings I used:

My background graphic is 1200 x 800 px.
I set the characters' baselines in the room script:

Code: ags
function room_AfterFadeIn ()
{ cUpperNPC.Baseline = 809;
cLowerPlayer.Baseline = 807; 

The lower cage object's baseline is set at 808, the upper cage's at 810.

Khris



I'm not seeing the individual sprites, the upper cage's bottom is part of which sprite? If you look at my post you can see that my first sprite is upper back wall, upper floor and lower bars, all of which are "in-between" the characters in a layers sense.

You can also use a different setup: the upper cage's top and the front and right bars of both cages will always cover both characters, so you can put them in a sprite and give that the lowest baseline. Then put just the upper cage's bottom in-between the characters.

(You should also use the before fadein event / room_Load function, or the baseline change will be visible in-game.)

TheEyess

The upper cage's bottom part is part of the lower sprite, as in your example. The back parts of both cages are part of the background and do not belong to the sprites.

Thanks for the other hints aswell.

Khris

You have a highres game, I'd try moving the baselines further apart. It's possible that AGS uses a lower resolution internally, and that for instance 807 and 808 end up being the same coordinate.

TheEyess

Tried it with 50px between the chars and objects, didn't change anything... I'll try the option with the cage top in a separate sprite next.

Khris

Wait, are you sure the function runs at all? Because the objects' baselines seem to be correct, but if you forgot to link the after_fadein function, it would explain why the NPC is behind the sprite.

TheEyess

I'm not sure what you mean by linking the function I'm afraid, I used the code mentioned earlier in the room script. It's not unlikely at all that I'm missing something codewise tho..  :X

Khris

Well, if you typed or pasted
Code: ags
function room_AfterFadeIn() {
}

into the room script, the function won't run until you also put room_AfterFadeIn into the room events table.

What you usually do, like with all other events, is click the [...] button so AGS links and creates the function for you.

TheEyess

Good Lord, I really forgot doing that. Just tried and that did the trick. Thank you so much, I would have never guessed that it was down to that... Thanks a lot!

SMF spam blocked by CleanTalk