×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31

    error shifting between displays

    the following code do not work, gs is a FullCanvas.

    when i call the method showGameScreen from commandAction the canvas are not displayed, but if i call it right after i have set the display to be the List object, it works.

    i have checked to se that the method showGameScreen is called, and the run() method of the GameScreen are called.

    i used the template from nokias guide for game developers, that show a example of a menu structure.

    the code is a simple version, but still i doesn't work.

    private void showMainMenu() {
    List l = new List("game menu",List.IMPLICIT);
    l.setCommandListener(new CommandListener() {
    public void commandAction(Command c,Displayable d) {
    showGameScreen();
    }
    });

    if ( gs != null && gs.gamepaused )
    l.append("Continue",null);
    else
    l.append("New Game",null);
    l.append("Options",null);
    l.append("Instructions",null);
    l.append("Highscore",null);
    l.append("About",null);
    l.append("Exit",null);

    display.setCurrent(l);
    }

    public void showGameScreen() {
    display.setCurrent(gs);
    gs.run();
    }

    please help im getting mad....

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    393
    What emulator/phone (sw version) do you face the problem on? Please post the GameScreen code as well.

    [N]/Forum Nokia

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31
    the run method looks as follows , cant post the hole GameScreen class its very BIG.


    public void run() {


    while (GameNotDone) {
    initplayer(); // sets player pos and so on
    initlevel(); // decode level structure for current level

    while (LevelNotDone ) {
    handleKey();
    handleAI();
    handleBullets();

    paintBuffer();

    repaint(0,0,96,65);
    serviceRepaints();

    Thread.yield();
    try {
    Wait(50);
    } catch (InterruptedException ie ) {}

    }
    currentlevel++;
    }

    }


    it works fine if its called from outside the commandAction method.




    thanks

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    393
    Is your GameScreen a different thread, in other words why are you calling gs.run() instead of doing a gs.start() (if it is a thread). Game loop should be in a different thread.

    Probably that is the issue because user input events and repaint events are taking too much time within the same thread to give the desired result.

    Let me know if it works.
    [N]/Forum Nokia

  5. #5
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113
    pekkert
    I've noticed that Series40 switch screens only after returning from your method.

    Try not calling run(), it should switch screen.

    You should launch game thread from showNotify() handler of a target Canvas. You can also try nmital's solution just to start it.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31
    it all runs in the same thread, ive tried to use many threads but found single thread to be fastest.

    i had some problems , with the loop taking up to much time so the system threads would not run well. making key events act weird.

    ill try caling the run() from showNotify(), seems like a good way to do it ...


    thanks

  7. #7
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113
    pekkert
    it all runs in the same thread, ive tried to use many threads but found single thread to be fastest.

    Well, it's geenerally recommended to use less threads.
    I also try using one unless second one can offer some really reasonable functionality.

    However, this means tricky synchronization. Be ready to the fact, that you'll have to solve similar issues rather oftem.

    ill try caling the run() from showNotify(), seems like a good way to do it ...
    It's not THAT good solution, because it violates the idea of Runnable and run(), it can confuse those who will maintain your app and yourself, rename it somehow.

    Have also other tip for this tricky synchronization. Have a closer look at Display.callSerially(). I find it very useful for packing everything in a single thread

  8. #8
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31
    i have a question that concerns threads.

    are the Thread that runs my code, also used by the application manager for other things. so i makes my code hang some time.

    how many threads does the system runs and what are they used for.

  9. #9
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113
    I would recommend you to start a new topic.

    It's different issue, thread professionals might not look at "shifting displays" problem.
    Also it will simplify for others reusing your experience, when using search.

    And anyway, it clearly quite other question

  10. #10
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31
    i have tried to implement the use of callserially(gs) and it works
    my canvas i shown, but it gives me at new problem. now my
    key events are not handled. nothing happens if i press a key

    :-(

    i have also tried to use showNotify() and start my loop from there, but it never gets called. the only way i can show my canvas i by using callserially.

    either im doing something wery wrong or this display shifting are not implemented wery well..

    i tried to run my game loop i a new thread , but it dosent help.

    need help...

  11. #11
    Registered User
    Join Date
    Jul 2003
    Location
    Finland, Tampere
    Posts
    1,113
    pekkert
    either im doing something wery wrong

    Looks so. Seems like you don't understand synchronisation issues well enough.

    Don't you forget to exit your code (not call run() manually)after calling callSerially()?

    Do you call repaint() after callSerially()?

    Post here critical parts of your code.

    Please, critical only

Posting Permissions

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