Does pixel perfect detection work while a character is animating? Say the character had an animation where he flung out a sword and if the player touched him, he would die, would PP detection apply to an animating character?
Yes, if pixel-perfect click detection is turned on.
Pixel perfect detection only works on a point.
I can't think of anything other than a brute force test like this:
#define MAXW 32 // this should be even
#define MAXH 64
// returns 1 if touching, 0 if not
// only works if no other characters are also overlapping
// if there are any, turn them off first
// both characters should have "No Interaction" unchecked
// untested for objects or GUI elements in front of the characters
function AreCharactersTouchingPP(int charA, int charB) {
// do a bounding box check first
int dx = character[charA].x - character[charB].x;
int dy = character[charA].y - character[charB].x;
if (dx*dx > MAXW*MAXW || dy*dy > MAXH*MAXH) return 0;
// find the overlapping part
int leftX = character[charA].x;
int rightX = character[charB].x;
if (dx < 0) {
// swap
leftX = rightX;
rightX = character[charA].x;
}
int topY = character[charA].y;
int bottomY = character[charB].y;
if (dy < 0) {
// swap
topY = bottomY;
bottomY = character[charA].y;
}
// convert room coordinates to screen coordinates
leftX = leftX - GetViewportX();
rightX = rightX - GetViewportX();
topY = topY - GetViewportY();
bottomY = bottomY - GetViewportY();
// iterate over the overlapping part
int touch = 0;
int thisRoom = character[charA].room;
int x = leftX - MAXW/2;
while (x <= rightX + MAXW/2) {
int y = topY - MAXH;
while (y <= bottomY) {
int frontChar = GetCharacterAt(x, y);
int backChar = charA;
if (frontChar == charA || frontChar == charB) {
if (frontChar == charA) backChar = charB;
// hide the front character
character[frontChar].room = 999;
if (GetCharacterAt(x, y) == backChar) {
character[frontChar].room = thisRoom;
return 1;
}
// restore the front character
character[frontChar].room = thisRoom;
}
y++;
}
x++;
}
return 0;
}