3

So I was trying to create a platformer game using HaxeFlixel, but I ran into a problem: after a FlxSprite object's x value passes 648, FlxG.collide doesn't seem to work at all. Here is a gif of the problem. As you can see, it works fine when the player's x is < 648, but when it becomes greater the FlxG.collision stops working.

The level is made of objects of the class Wall which extends FlxSprite with the only difference being that it's constructor loads the wall graphic and sets its immovable property to true. FlxG.collide is being called with player as the first argument and a FlxGroup (containing the walls) as the second argument. I'm not sure that it matters but the FlxState's super.update is being called before FlxG.collide.

MightyAlex200
  • 81
  • 1
  • 5
  • 2
    You may need to change `Flxg.worldBounds` to something bigger to get collisions working as [this issue](https://github.com/HaxeFlixel/flixel/issues/539) says – Justo Delgado May 04 '17 at 21:21

1 Answers1

5

Okay so I took a look at the HaxeFlixel source code (specifically the FlxG.overlap private function (line 363)), and I found that it only checks for objects inside the worldBounds FlxRect. After I knew that, all I had to do was set the bounds of that rect, which can be done with FlxG.worldBounds.set(?X:Float = 0, ?Y:Float = 0, ?Width:Float = 0, ?Height:Float = 0).

MightyAlex200
  • 81
  • 1
  • 5