Character GetAtScreenXY (Multiple characters)

Started by TMuh, Thu 06/02/2014 16:32:22

Previous topic - Next topic

TMuh

Hi,

Im using Character.GetAtScreenXY for detecting if there is an enemy at the location of players sword. It works fine, but the problem is when there is multiple characters at the same location. So is there way of identifying all overlapping characters in some x,y position?

Scavenger


Khris

It should be noted that this will compare the rectangular bounding boxes of the two objects.
To detect multiple characters at a single coordinate location, you could try turning all the characters unclickable, then turn them clickable for the test. I don't know if this will work during a single game loop though.

Code: ags
bool IsAt(this Character*, int x, int y) {
  this.Clickable = true;
  bool r = Character.GetAtScreen(x, y) == this;
  this.Clickable = false;
  return r;
}

  // enemies have IDs 3-9
  int i = 3;
  while (i < 10) {
    if (character[i].IsAt(sword_x, sword_y)) character[i].hit();
    i++;
  }

TMuh

Thank you both. I got it working with that clickable thing.

SMF spam blocked by CleanTalk