2
\$\begingroup\$

I make a MenuScene when my Game loads, which grabs some intro text from levelData and displays it and a button to start playing the level. When the MenuScene is created and displayed in onLoadComplete() it's fine. However when I display it again when advancing the level (levelData is loaded with new data and the MenuScene reset) it freezes, showing the game at the point the level was beaten. The menu is not displayed at all. I'm just calling

loadIntro();
this.mScene.setChildScene(this.mIntroScene, false, true, true);
this.mEngine.stop();

to display the MenuScene (the same both times, it works the first time but not the second), where loadIntro() is

private void loadIntro() {
            this.mIntroScene = new MenuScene(this.mCamera);

            final TextMenuItem intro = new TextMenuItem(-1, mFont, levelData.getIntroText());
            intro.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
            intro.setSize(400, 150);
            this.mIntroScene.addMenuItem(intro);

            final SpriteMenuItem startMenuItem = new SpriteMenuItem(MENU_START, this.mMenuStartTextureRegion);
            startMenuItem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
            this.mIntroScene.addMenuItem(startMenuItem);

            this.mIntroScene.buildAnimations();
            this.mIntroScene.setBackgroundEnabled(false);
            this.mIntroScene.setOnMenuItemClickListener(this);

    }

What am I doing wrong?

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Have you run through the code with a debugger? Do you know where the problem is? My guess is that something is not be initialised properly. \$\endgroup\$
    – thedaian
    Commented Aug 24, 2011 at 23:11
  • 1
    \$\begingroup\$ Is it possible to use a separate thread for the game action? I'm wondering if the menu being activated is consuming the current thread (this is only a guess). \$\endgroup\$ Commented Aug 25, 2011 at 2:37
  • 1
    \$\begingroup\$ @Randolf rewriting into a separate thread fixed it, write up an answer so I can accept it! \$\endgroup\$
    – fredley
    Commented Aug 25, 2011 at 10:46

1 Answer 1

4
\$\begingroup\$

Is it possible to use a separate thread for the game action? I'm wondering if the menu being activated is consuming the current thread (this is a guess based on my experience in programming applications in Java that use menus).

I suspect that what's going on is that you have one main thread, and that by activating the menu your code is temporarily halted while the user decides what to do with the menu.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .