Author Topic: [FlxObject overlap] fix for working with offsets  (Read 1770 times)

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
If you are manually setting an offset on a FlxSprite using [FlxObject overlap:withObject] doesn't respect your offsets.

To fix add this to FlxSprite.m

Code: [Select]
- (BOOL) overlapsWithOffset:(FlxSprite *)Object;
{
    CGPoint _point = [self getScreenXY];
    float tx = _point.x + self.offset.x;
    float ty = _point.y + self.offset.y;
    _point = [Object getScreenXY];
    if ((_point.x + Object.offset.x <= tx - Object.width  ) || (_point.x + Object.offset.x >= tx + width) || (_point.y + Object.offset.y <= ty - Object.height) || (_point.y + Object.offset.y >= ty + height))
        return NO;
    return YES;
}

and this to FlxSprite.h

Code: [Select]
- (BOOL) overlapsWithOffset:(FlxObject *)Object;
« Last Edit: Sat, Jun 18, 2011 by initials »
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart