×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    16

    Unhappy How should a proper game loop be constructed?

    Please explain me where the error is:

    I have a main game loop in a run() method of a Thread Object.
    It's contents is simple:

    Code:
    1 switch (gameUtil.getCurrentDisplayNumber())
    2   case GameUtil.CANVAS_GAME:
    3   {
    4      ((Canvas)gameUtil.getCurrentCanvas(GameUtil.CANVAS_GAME)).repaint();
    5      ((Canvas)gameUtil.getCurrentCanvas(GameUtil.CANVAS_GAME)).serviceRepaints();
    6      break;
    7   }
    8   case GameUtil.CANVAS_GAME_OVER:
    9   {
    10      ((Canvas)gameUtil.getCurrentCanvas(GameUtil.CANVAS_GAME_OVER)).repaint();
    11      ((Canvas)gameUtil.getCurrentCanvas(GameUtil.CANVAS_GAME_OVER)).serviceRepaints();
    12      break;
    13  }
    The main game logic is inside the paint method of the game canvas.
    I utilize the fact that paint() is called all the time and I do all movement calculations
    inside this method.

    Now, when somewhere inside this paint() method I detect that the player has lost all lives
    I want to switch to a Game Over screen. So I call:

    Code:
    gameUtil.setCurrentDisplayNumber(GameUtil.CANVAS_GAME_OVER);
    Display.getDisplay(gameUtil.getGameMIDlet()).setCurrent(gameUtil.getCurrentCanvas(gameUtil.getDisplayNumber()));
    This call is made somewhere inside the paint() method of the game canvas.

    And the problem is that on some phones the game over canvas shows up but is deadlocked.
    I mean the paint() method of the game over canvas is called only once and never again.

    I noticed that removing the serviceRepaints() call from the 5th line solves the problem but
    it result in animation frames being dropped (at least it looks like this).

    So I want to find out what is causing the problem - what I'm doing wrong and how to correct it.

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    16

    Re: How should a proper game loop be constructed?

    I moved the game logic out of the paint() method and now use the latter only for painting and everything is OK now.

  3. #3
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: How should a proper game loop be constructed?

    Hi,
    please dont use any code that is used for calculation inside the paint method.It will cause serious probleems.
    Regards
    Soku

Similar Threads

  1. Great game Wappo
    By geonofear in forum News and Announcements
    Replies: 2
    Last Post: 2007-01-03, 12:00
  2. Main loop of MIDP2 game?
    By pachura in forum Mobile Java General
    Replies: 1
    Last Post: 2006-03-07, 09:16
  3. RunL() method is not being called
    By dotcdotc in forum Symbian
    Replies: 9
    Last Post: 2004-12-13, 11:25
  4. Best game loop approach?
    By marcpalmer in forum Mobile Java General
    Replies: 1
    Last Post: 2003-09-01, 10:26
  5. Game loop question
    By tinkezione in forum Mobile Java General
    Replies: 7
    Last Post: 2002-12-31, 08:14

Posting Permissions

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