Can't figure out setTileProperties callback

  • I'm trying to set a callback for a door tile in an FlxTileMap so that I can move between rooms when the player touches a door.

    private var door:FlxTile;
    door = new FlxTile(_mWalls, 2, 16, 16, true, FlxObject.ANY);
    _mWalls.setTileProperties(3, FlxObject.ANY, moveRoom(door, _player), Player);

    _player is a Player object which extends flxSprite. The callback is:

    public function moveRoom(Tile:FlxTile, Object:FlxObject):Void
    	trace("you touched a door");

    However when I do this I receive the message:

    source/PlayState.hx:83: characters 46-69 : Void should be Null<flixel.FlxObject -> flixel.FlxObject -> Void>
    source/PlayState.hx:83: characters 46-69 : Void should be flixel.FlxObject -> flixel.FlxObject -> Void
    source/PlayState.hx:83: characters 46-69 : For optional function argument 'Callback'

    The full class is here if that would be more helpful:

  • administrators

    You need to pass a reference to the function, not call it. This should work:

    _mWalls.setTileProperties(3, FlxObject.ANY, moveRoom, Player);

  • Sweet that did it along with removing the parameter names from the moveRoom function.

Log in to reply