How to make objects appear in front of/ covering NPCs?

Started by Javier Tolstoi, Thu 31/08/2017 16:23:08

Previous topic - Next topic

Javier Tolstoi

Hello,
this might be a highly noobish question, please answer it although:
How do I make objects appear in front of NPCs?
For example, I'm having an NPC with a beard, and this beard is an object (because the player has to cut it at some point).
However, the NPC is covering the beard, while the latter is supposed to be in front of his face.
Can you help me?

Snarky

The distance order of things on screen is determined by their baseline: the higher up on screen the baseline is, the farther away. If you think of each object, character or walkbehind as a flat, vertical cutout or screen facing the camera, the baseline is where it would touch the floor. So things with a higher baseline (higher on screen, that is; in other words a lower number) will be drawn behind things with a lower one.

The baseline of characters is the character.y position (which, by default, is the bottom of their sprite). The baseline of objects is also the bottom of their sprites by default, but if the beard doesn't go all the way to his feet, that will still be higher on screen than the bottom of the character sprite. So you'll need to override the object baseline and set it to some value below the character, e.g.:

Code: ags
oBeard.Baseline = cBeardedNpc.y + 1;


In general, using a separate object may not be the best solution for this task. Usually you'd just draw two versions of the NPC, with and without beard, set them up as separate views, and change from the bearded to the non-bearded view when the player cuts the beard.

Crimson Wizard

Quote from: Snarky on Thu 31/08/2017 16:39:25
In general, using a separate object may not be the best solution for this task. Usually you'd just draw two versions of the NPC, with and without beard, set them up as separate views, and change from the bearded to the non-bearded view when the player cuts the beard.

I would also add that even if you'd like beard as separate object, it is better to use character as a beard, regardless of how weird that may sound :),  because characters may change rooms, but objects cannot, so you would end up making separate beard objects in every room in your game!

SMF spam blocked by CleanTalk