×

Discussion Board

Results 1 to 3 of 3

Thread: Thread probs.

  1. #1
    Regular Contributor
    Join Date
    Sep 2003
    Posts
    60

    Thread probs.

    I'm having difficulties with Threads.

    I have a List menu screen that when "New Game" is selected I want to run a small intro screen. The intro is a FullCanvas runnable object and has a small animation(i.e. it loops about 100times or so) then I want to return to the menu.

    The code is something like:

    void startUp()
    {
    // show menu list
    Display.getDisplay(MIDlet).setCurrent(menuList);
    }

    void CommandAction(......)
    {
    // when "New Game" is selected then show intro
    Display.getDisplay(MIDlet).setCurrent(intro);
    // then return to menu
    Display.getDisplay(MIDlet).setCurrent(menuList);
    }

    Problem is that I want to finish the intro Thread and *THEN* set the display to the menu object again.

    Basically how do I do this? I can't seem to get the main Thread to wait until the other intro Thread completes.

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    You need to set the menu screen at the end of the run() method of your intro screen, instead of immediately after you display the intro screen. Something like:
    Code:
    public class Intro extends FullCanvas implements Runnable {
      MIDlet midlet;
      Displayable nextScreen;
      // ...
      public Intro(MIDlet midlet, Displayable nextScreen) {
        this.midlet = midlet;
        this.nextScreen = nextScreen;
        // other initialization
      }
      // ....
      public void run() {
        // run animation
        // and when you're done animating:
        Display.getDisplay(midlet).setCurrent(nextScreen);
      }
    }
    So in the commandAction() you just set the Intro as the displayable, start the thread, and when the thread reaches the end it set the displayable back to the menu.

    shmoove

  3. #3
    Regular Contributor
    Join Date
    Sep 2003
    Posts
    60
    Thanks shmoove, I'll give that a try.

    Basically this intro is really a loader screen that's displayed while I load sprites, level, etc. So If I call a func MIDlet.loadLevel() when the intro Thread is finished to load the images and don't change the dislpay yet. so.. this is off the top of my head, sorry if not 100%

    // Intro class
    public void run() {
    // run small animation
    // and when done animating:
    MIDlet.loadLevel();
    }


    //MIDlet class
    public loadLevel()
    {
    // load sprites, etc
    loadSprites();
    loadLevel();
    initGame();

    //change Display to game canvas.
    Display.getDisplay(this).setCurrent(gameCanvas);
    }

    The intro image will be shown and then everything is loaded and then I can change the dislplay to the game canvas as it's ready to play.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×