FlxButtonPlus Callback function with arguments



  • I'm making a small game with a friend, mostly for learning, where we want to create a level select screen. To do this, we use a for loop to make individual buttons.

    for (i in 0..._amountOfLevels - 1)
    {
    _levelButtons[i] = new FlxButtonPlus(_buttonX, _buttonY, GoToLevel(i), 128, 128);
    _levelButtons[i].textNormal.size = 100;
    _levelButtons[i].textHighlight.size = 100;
    _levelButtons[i].updateActiveButtonColors([FlxColor.CYAN]);
    _levelButtons[i].updateInactiveButtonColors([FlxColor.GRAY]);
    _buttonX += 256;
    }

    This won't work because the callback function does not support arguments. I googled for a while, and discovered that the original Flixel FlxButtonPlus supported using function arguments. Is there any alternative for HaxeFlixel?

    Thanks for any answer.



  • Try this:

    _levelButtons[i] = new FlxButtonPlus(_buttonX, _buttonY, GoToLevel.bind(i), 128, 128);
    


  • @DleanJeans said in FlxButtonPlus Callback function with arguments:

    Try this:

    _levelButtons[i] = new FlxButtonPlus(_buttonX, _buttonY, GoToLevel.bind(i), 128, 128);
    

    Thanks, it worked.


Log in to reply
 

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