Player falls through other sprites even though FlxG.collide()



  • Hello,
    As TiledMaps are causing me problems due to artifacts which are annoying and would take my game to a bad user experience, I tried to export the TiledMap as a png image, willing to use it as a sprite colliding with other entities.

    The map belongs to the class Ground extends Sprite of which, the only significant line of code is in the new function, loadGraphics(AssetPaths.ground__png,false).

    Even though I add FlxG.collide(player,ground) to the update loop, the player falls through the ground.
    When I've been using tiledmaps, although the annoying artifacts, the collision worked perfectly with FlxG.collide(walls,player).

    P.S. I tried to create another entity ( a random enemy) just under the player. When the game starts, the player begin to fall (as gravity would normally allow to do), it pushes the enemy down for about a hundred pixels, then it continues to fall through it.

    It's very strange.
    FlxG.collide() is working for TiledMap + Sprite but not for Sprite + Sprite.

    Is it a bug?


  • administrators

    You might need to set the ground's immovable property to true:

    http://api.haxeflixel.com/flixel/FlxObject.html#immovable



  • I think you want pixel perfect collision, otherwise, the collision is based on bounding boxes. Like FlxG.pixelPerfectOverlap(), don't know if there is one built-in for collsions.



  • Did you try FlxG.worldBounds.set()?



  • Also, it should be noted, with my version, that a sprite will not collide with another sprite if immovable is set to true and FlxPath is set for the other sprite.

    Space Castle is a free retro style platformer game with a mystery storyline and made using the haxeflixel library.

    0

  • administrators

    @galoyo Yes, that's because FlxPath temporarily sets immovable to true for the object it's applied to, and two immovable objects do not collide.



  • Nothing to do.
    The player continues to fall. Very frustrating.


  • administrators

    Can you share some code so we can reproduce this?



  • I have found the problem. I've used this image as map.
    http://imgur.com/a/hiqQ4
    As I can see, HaxeFlixel does not recognize Alpha Trasparency in images, any way to do so?


  • administrators

    You mean in collision detection? No. Otherwise yes.

    There's FlxG.pixelPerfectOverlap() like @starry-abyss mentioned, but that's only for overlap checks, not collisions. If you want pixel-perfect collisions, you need something like Nape, Flixel only has rectangular hitboxes built-in.



  • Thanks for Your support.


  • administrators

    It might be better to fix your original issues with "artifcats" rather than working around tilemaps (looking at the image you posted, a tilemap really seems like the best tool for the job).

    Is your issue by chance the same as the one described here?

    http://forum.haxeflixel.com/topic/39/tilemap-tearing-desktop-targets/


Log in to reply