Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Pax Animo on Sat 30/12/2023 01:38:40

Title: Fading all objects of a certain type
Post by: Pax Animo on Sat 30/12/2023 01:38:40
Heya,

So, basically I'm trying to fade all objects of a certain type when a player character walks behind them, for example trees:

function obj_fade(int obj_id) {
 
  if (player.IsCollidingWithObject(object[obj_id])) {
    if (object[obj_id].Transparency != 40) {
    object[obj_id].Transparency++;
    //Wait(0); //ignore
    }
  }
  else {
    object[obj_id].Transparency = 0;
  }
}
 
function room_RepExec()
{
  obj_fade(oTree2.ID);
  obj_fade(oTree3.ID);
}

What would be the easiest way to run one line of code in RepExec to check if the charter is behind object type tree?

Cheers in advanced as always.
Title: Re: Fading all objects of a certain type
Post by: Khris on Sat 30/12/2023 12:08:05
You can automate this almost completely:

1. create a custom bool property (like "walkbehind_fade") and set it to true for all relevant objects

2. call this to your global rep_exec:

void HandleFadingObjects() {
  for (int i = 0; i < Room.ObjectCount; i++) {
    if (!object[i].GetProperty("walkbehind_fade")) continue; // skip other objects
    int dy = object[i].Y - player.y;
    if (dy < 0) continue; // player is in front of object
    int hw = Game.SpriteWidth[object[i].Graphic] / 2;
    int dx = object[i].X - player.x;
    if (dx < -hw || dx > hw) continue; // player not behind horizontally
    if (dx < 0) dx = -dx;
    object[i].Transparency = (hw - dx) * 100 / hw;
  }
}

Not tested!
Title: Re: Fading all objects of a certain type
Post by: Pax Animo on Sat 30/12/2023 22:07:15
Thanks Khris, I've not tested your code either but I had completely forgotten about custom properties and I see where you was going with your code snippet,i shall go from there.