Nifty – ScreenController.onAfterStartScreen() :roll: (19 posts)

  • Profile picture of glaucomardano glaucomardano252p said 6 months ago:

    I’m trying to figure out how to do things after the screen is started, in other words, after the elements are rendered on screen. The ScreenController.onStartScreen() doesn’t do what I’m wanting, it is called before the elements are rendered. I have a progress bar in my screen, and I’m trying to make the progress bar starts after the screen is started, otherwise, the things will be loaded but the progress bar won’t be rendered :/ . Any ideas?

  • Profile picture of kernproblem kernproblem7p said 6 months ago:

    are you using the boolean load=true?
    if you click a button run a void like:

    public void load() {
    load=true;
    nifty.gotoScreen("loadscreen");

    in the update():

    if(load==true){<map,player.... erverythink else what you want to load>
    load=false;
    loaded=true;}
    if(loaded==true){
    erverything from the normal update loop
    }

    but can you poste your code if that dosn’t help you?

  • Profile picture of glaucomardano glaucomardano252p said 6 months ago:

    …if you click a button run a void like:…

    It’s the problem. The start screen have just a progress bar, no buttons. The progress bar have to be started automatically. Btw, it’s alreay have a load var. It seems be an easy thing, but it’s not. I think it’s almost impossible. The start screen code is this :

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package rhythmgame.nifty.control.screen;
    
    import de.lessvoid.nifty.Nifty;
    import de.lessvoid.nifty.screen.Screen;
    import rhythmgame.nifty.control.progressbar.ProgressBar;
    import rhythmgame.nifty.control.progressbar.ProgressBarControl;
    
    /**
     *
     * @author Glauco Márdano
     */
    public class StartScreenControl extends RhythmGameScreenController {
    
        private ProgressBar loadingBar;
        private boolean load;
    
        @Override
        public void bind(Nifty nifty, Screen screen) {
            super.bind(nifty, screen);
            loadingBar = screen.findControl("startLoadingBar", ProgressBarControl.class);
        }
    
        @Override
        public void onStartScreen() {
            super.onStartScreen();
            loadStuffs();
        }
    
        @Override
        public void loadStuffs() {
            getApp().loadStuffs(loadingBar);
            load = true;
        }
    
        @Override
        public void update(float tpf) {
            super.update(tpf);
            if (load) {
                goToScreen("mainMenuScreen");
                getNifty().removeScreen("startScreen");
                load = false;
                getStateManager().detach(this);
            }
        }
    }
    
    <?xml version="1.0" encoding="UTF-8"?>
    <nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd"&gt;
      <!-- +++++++++++++++++++++++++++++++++++++++ -->
      <!-- start screen -->
      <!-- +++++++++++++++++++++++++++++++++++++++ -->
        <useStyles filename="Interface/Styles/styles.xml" />
        <useControls filename="nifty-default-controls.xml" />
        <useControls filename="Interface/Controls/controls.xml" />
        <screen id="startScreen" controller="rhythmgame.nifty.control.screen.StartScreenControl">
            <layer id="startLoadingLayer" childLayout="horizontal">
                <panel height="10%"/>
                <panel id = "startLoadingPanel" childLayout="vertical" align="center" valign="center" height="32px" width="80%">
                    <control image="Interface/Skins/ProgressBar/inner-orange.png" id="startLoadingBar" name="progressBar" align="center" valign="center" width="100%" height="100%" progress="0f" direction="horizontal" progresstext=""/>
                </panel>
                <panel height="10%"/>
            </layer>
        </screen>
    </nifty>
    
  • Profile picture of kernproblem kernproblem7p said 6 months ago:

    do you think some thing like wait 1 second before loadstuff(); will work?
    edit: do you need the progressbar? long loading time?

  • Profile picture of glaucomardano glaucomardano252p said 6 months ago:

    It looks nifty isn’t run in another thread, then if I use wait() it’ll stop both loadStuffs() and the nifty itself, then it will do nothing. The only way to use wait() is calling it in another thread I think, but I don’t wanna to use any threads on this stage. It’s not needed. Also, it’s a poor solution.

  • Profile picture of kernproblem kernproblem7p said 6 months ago:

    I think its almost impossible

    Also, its a poor solution.

    and you can use a tiner to wait one second

    loadtimer = loadtimer + tpf;

  • Profile picture of glaucomardano glaucomardano252p said 6 months ago:

    I know, I use Timer in-game to synchronize the sound with the move bars, but risking a time is not a good approach. Also, who will garantee that the screen will be started in 1 second :roll: ? It might takes more than expected. It might be a solution, but I don’t like it.

  • Profile picture of kernproblem kernproblem7p said 6 months ago:

    ok, i don’t have any other solutions at the moment, but i will post it when i find some thing :) and good luck with your game!

  • Profile picture of glaucomardano glaucomardano252p said 6 months ago:

    Thanks, I really appreciate your help. Good luck too ;) .

  • Profile picture of ractoc ractoc24p said 6 months ago:

    When you display the screen, you call something like fromXML or gotoScreen in another class, your main class probably.
    This method returns the moment the screen is displayed.

    You can use this by calling a method like startProgressBar or something right after your call to fromXML.

  • Profile picture of wezrule wezrule201p said 6 months ago:

    your doing your loading and rendering in the same frame, if you wait a frame before doing the loading you should see your Progress bar screen first.

    This might help http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:loading_screen

  • Profile picture of glaucomardano glaucomardano252p said 6 months ago:

    @ractoc: Hmmm. Yeah, it really makes sense, starting the progress bar out of the screen controller and after it’s displayed might works, I didn’t try it yet. I’ll try it when I get home, thanks!

    @wezrule: Yeah. I already read that page, and I should do how it does, by loading the stuffs out of the screen controller. I’ll try it, thanks!

  • Profile picture of glaucomardano glaucomardano252p said 6 months ago:

    No sucess too. I did it in simpleInitApp():

    nifty.gotoScreen("startScreen");
    loadStuffs();
    

    But the loadStuffs() method is still being called before the screen is displayed. I tried to go to the start screen in simpleInitApp() method and when the app starts I call loadStuffs() in simpleUpdate() too, but it does the same thing. As I said before, it seems be a easy thing to do, but it isn’t. Anyway, thanks for the helps.

  • Profile picture of pspeed pspeed815p said 6 months ago:

    If both of those calls are on the same thread then of course you will never see the screen.

    You are basically saying:
    -hey, nifty, goto a screen when you get a chance
    -in the mean time, let me load this stuff blocking the thread that would update you

    When you block the render thread, nothing gets rendered.

  • Profile picture of glaucomardano glaucomardano252p said 6 months ago:

    hmmmmmmm. Yeah! The render thread xD . Then I’ll try to run the loadStuffs in another thread.