2 Replies Latest reply: Dec 9, 2010 11:30 AM by smon RSS

    'Standard' way of swapping displays (beginners game question)?

    smon
      hi folks - just wondering if anyone can give me a quick, high level answer on how I should handle swapping screens/displays in my little j2me game.

      The game code works okay, but currently there's just one screen (ie. the game) and the midlet just 'launches' straight into it.
      public void startApp() {
      Display display =Display.getDisplay(this); 
      myGameCanvas.start(); // Added
      display.setCurrent(myGameCanvas); 
      }
      say the user opens the game, plays a while and eventually it's game over, I'm a little confused how to then display a new screen (ie. 'game over').

      Should I just call display.setCurrent() from the game loop, or does this have to be called from the Midlet?

      Can I call back 'up' to the midlet from the game class?

      Should there be a controller class handling displays?

      What's the 'standard' way of doing this?

      thanks in advance..
        • 1. Re: 'Standard' way of swapping displays (beginners game question)?
          DarrylBurke
          smon wrote:
          Should I just call display.setCurrent() from the game loop, or does this have to be called from the Midlet?
          What's the difference? The method call works the same way in any case.
          Can I call back 'up' to the midlet from the game class?
          Define "back 'up'". The MIDlet is the application, not a visual element.
          Should there be a controller class handling displays?
          Depends on the complexity of the application.
          What's the 'standard' way of doing this?
          Um, <tt>display.setCurrent(...)</tt>

          db
          • 2. Re: 'Standard' way of swapping displays (beginners game question)?
            smon
            Darryl Burke wrote:
            What's the 'standard' way of doing this?
            Um, <tt>display.setCurrent(...)</tt>

            db
            err, no, I don't mean which method do you call. Generally (at a higher level), is there a standard approach to handling swapping screens, ie. is it a recommended practice to implement a controller class, or do programmers generally just litter their code with calls to display.setCurrent() as and when needed?

            Personal choice I guess, I just thought I'd seek opinion though from some more experienced j2me'ers as to how they do it.

            Depends on the complexity, sure. Though even for small apps implementing a controller sounds a much cleaner solution to me.