[SOLVED] Problem with FlxG.overlap

  • As the title says, I'm having trouble with FlxG.overlap
    What I'm trying to accomplish is when the player is overlapping the desk and presses the spacebar, you interact with it.

    override public function update(elapsed:Float):Void
    		FlxG.overlap(_player, desk, onDeskOverlap);
    	private function onDeskOverlap():Void
    		if (FlxG.keys.justPressed.SPACE)

    When I do this code it outputs errors

    Not too sure if this affects it, but here's what the variables look like

    private var _player:Player;
    public var desk:FlxSprite = new FlxSprite(375, 29);

    All of this is in Playstate

  • try this code...

    private function onDeskOverlap(player:Player, desk:FlxSprite):Void


    private function onDeskOverlap(player:FlxSprite, desk:FlxSprite):Void

    if desk is a tile then use FlxTilemap
    also, I use... if (FlxG.keys.anyPressed(["SPACE"]))

  • @galoyo I got the game to run, but it doesn't show anything in the logs when I'm overlapping it or pressing spacebar...

  • Are you using FlashDevelop? At the log window of that Ide, click the start tracking button. In the hx file, try this... trace("Interact");


  • @galoyo Nothing, it also doesn't collide either... not sure if that bit of info helps but I can link you to the WIP source code: https://github.com/ninjamuffin99/SickDay/blob/master/source/PlayState.hx
    I don't use github too often but I think there's also the other files there if you want to peak at them

    Edit: I am using FlashDevelop

  • I am not sure what the problem is. the modified code works. I can see the trace text when they collide.

  • @galoyo Strange, it still doesn't work for me on the desk object, but I added in a bathroom object with nearly the exact same code and it works perfectly fine

  • yes that is strange. :)

  • i had an emitter that i forgot to add(emitter) to. the emitter still worked but did not when resetting the stage. took me forever to find that error.

  • I've added the same type of code to the TV & couch object, hoping that it was only the desk that wouldn't output to the logs, but turns out the TV is having the same issue as the desk

  • Another update: It seems when the x position of the player is greater than about 130, then it doesn't output anything to console

    I think it has something to do with what I have set for the FlxGame. Currently it's at 160, and when I set it to 600, the overlap stuff works...

  • @ninja_muffin99 add FlxG.worldBounds.set(0, 0, 650, 90); for your world size, it should help.

  • @Spw That seemed to fix the problem! Thanks!

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.