When my program running (Neko/html5/Any another) it dont show me buttons



  • Hi guys i noob in HaxeFlixel and try work with some tutor - but at first of it i look strange things in any tutors written i must get buttons when run this code - but i see only clearscreen ((( What the problem and how i can solve it ? Thanx

    Code^

    package;
    
    import flixel.FlxState;
    import flixel.FlxG;
    import flixel.ui.FlxButton;
    
    class MenuState extends FlxState
    {
        override public function create():Void
        {
            super.create();
    
            var button:FlxButton = new FlxButton(50, 50, "Click here", OnClickButton);
            add(button);
        }
    
        function OnClickButton():Void
        {
            trace("clicked!");
        }
    
        override public function update():Void
        {
            super.update();
        }
    }
    

  • administrators

    If you used the default template, the default state is PlayState. You could

    • move your code to PlayState
    • change the initial state to MenuState (this is defined in Main.hx)


  • Thanx but please can you tell little more about ) Im a totally newbie but learn so if you can little more info be real helpful) Yes oi make default HaxeFlixel project - so template too i think default


  • administrators

    Your project directory should have a Main.hx file with the following line:

    addChild(new FlxGame(640, 480, PlayState));
    

    PlayState is the InitialState argument. Check out the API docs for the FlxGame constructor:

    The class name of the state you want to create and switch to first (e.g. MenuState).

    http://api.haxeflixel.com/flixel/FlxGame.html?#new

    More generally, your game is always in a specific state (other engines also call this "scene" sometimes). That means if your InitialState is PlayState, MenuState will be inactive (until you switch to it), which is probably the reason you're only seeing a clear screen.

    A lot of games start with a state for the main menu (where the menu elements are created), then switch to a state for the actual gameplay (with gameplay objects like perhaps a player sprite). Switching states is done by using FlxG.switchState(). You could have any number of other states though.



  • Thanx ) I understand and do all needed changes - my problem are totaly solved now/ This passage with scenes and states do all at the right places ) Thanx for answer and thanx for good language and framework


Log in to reply