Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: TMuh on Thu 06/02/2014 16:32:22

Title: Character GetAtScreenXY (Multiple characters)
Post by: TMuh on Thu 06/02/2014 16:32:22
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?
Title: Re: Character GetAtScreenXY (Multiple characters)
Post by: Scavenger on Thu 06/02/2014 16:44:50
I think you want the AreThingsOverlapping (http://www.adventuregamestudio.co.uk/wiki/Room_functions#AreThingsOverlapping) function?
Title: Re: Character GetAtScreenXY (Multiple characters)
Post by: Khris on Thu 06/02/2014 17:14:33
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) Select
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++;
  }
Title: Re: Character GetAtScreenXY (Multiple characters)
Post by: TMuh on Sun 09/02/2014 11:45:16
Thank you both. I got it working with that clickable thing.