Player falls through other sprites even though FlxG.collide()
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?
You might need to set the
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
Also, it should be noted, with my version, that a sprite will not collide with another sprite if
immovableis set to true and
FlxPathis set for the other sprite.
@galoyo Yes, that's because
truefor the object it's applied to, and two
immovableobjects do not collide.
Nothing to do.
The player continues to fall. Very frustrating.
Can you share some code so we can reproduce this?
I have found the problem. I've used this image as map.
As I can see, HaxeFlixel does not recognize Alpha Trasparency in images, any way to do so?
You mean in collision detection? No. Otherwise yes.
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.
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?