Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
2  
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. –  thedaian Aug 24 '11 at 23:11
1  
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). –  Randolf Richardson Aug 25 '11 at 2:37
1  
@Randolf rewriting into a separate thread fixed it, write up an answer so I can accept it! –  fredley Aug 25 '11 at 10:46
add comment

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.