Author Topic: Suggestion: boolean return values on collideArray/overlapArray/etc in FlxG  (Read 1793 times)

caspervanest

  • Member
  • **
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Hey Adam and other flixellers,

I've got a suggestion for an improvement in the flixel collision code (FlxG).
What if you'd let all the collide and overlap-functions in FlxG return a boolean value indicating whether or not a collision has happened? Just like in FlxTilemap.collide?

That way, one could use the boolean value to see if no collisions had occured and maybe (for instance) call a hitNoting() function on a (player) sprite.
I'm using this myself, because I have some custom (slope) collision, but I thought others might find it useful as well?

Or is there a specific reason why those functions should NOT return a boolean value?
Cheers!
Casper

PS Here's an example of how I'm using it in my state.update function:
Code: [Select]
var playerCollided:Boolean = false;
if ( tilemap.collide(player) )
playerCollided= true;
if ( FlxG.overlapArray(slopes, player, player.hitSlope) )
playerCollided= true;

if ( !playerCollided)
player.hitNothing();

Gigaclon

  • Member
  • **
  • Posts: 87
  • Karma: +0/-0
    • View Profile
you could just set the collide variable to true in the collision function and test for it

caspervanest

  • Member
  • **
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Hmm yes that could also work, thanks!