Author Topic: Overlap being called twice  (Read 1357 times)

jaems

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Overlap being called twice
« on: Sat, Jan 10, 2015 »
I've googled around and there seems to be no elegant solution for this. How is it possible that this bug was never fixed?
I'm using HaxeFlixel to make an simple endless runner and when my player collides with an Enemy (part of a Sprite GRoup), the Enemy explodes and is .kill()ed.

I'm keeping a score counter, and it's evident from using trace() and the score that it's being called twice. This would be OK if the overlap was at least consistent, but it's not. Sometimes, it'll be counted ONCE, but almost always twice.

Here's some code. I really don't want to have to do a really ugly hack just to fix this (create a Bool for each object in the pool, and then have to reset the state of all of them).

Code: [Select]
FlxG.overlap(_player, _obstacles, playerTouchObstacle);
Code: [Select]
private function playerTouchObstacle(P:Player, E:Enemy):Void
{
trace("HIT");
explode(E.x, E.y);
E.kill();

_score++;
_hud.updateHUD(_score);
}
« Last Edit: Sun, Jan 11, 2015 by jaems »

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: Overlap being called twice
« Reply #1 on: Tue, Jan 27, 2015 »
I know this is old, but try changing:

FlxG.overlap(_player, _obstacles, playerTouchObstacle);

into:

if (!dead) FlxG.overlap(_player, _obstacles, playerTouchObstacle);

dca

  • Member
  • **
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Overlap being called twice
« Reply #2 on: Sun, Feb 15, 2015 »
Tried posting once before but don't know why it didn't appear

Code: [Select]
E.solid=false;
explode(E.x, E.y);
E.kill();

This should stop the double Overlap as E.solid turns off collision for the object.