Fading all objects of a certain type

Started by Pax Animo, Sat 30/12/2023 01:38:40

Previous topic - Next topic

Pax Animo

Heya,

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

Code: ags
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.
Misunderstood

Khris

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:

Code: ags
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!

Pax Animo

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.
Misunderstood

SMF spam blocked by CleanTalk