×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    7

    Screensize in MIDP2.0 GameCanvas class

    I have the following problem with a Nokia series 60 device:

    I'm using the MIDP2.0 GameCanvas class and set it to fullscreen like this:

    myCanvas = new Canvas(this);
    myCanvas.setFullScreenMode(true);
    myCanvas.setHeight();


    in Canvas class:

    public void setHeight()
    {
    DISP_HEIGHT = getHeight();
    yOffset = 13 + ((DISP_HEIGHT-208)/2);
    }

    Oddly, the function getHeight() still return the 144px of the non fullscreen mode. I need to calculate the yOffset to center the screen content for devices with different screen height (eg. Sony Ericsson 220px).

    Is there any possibility to get the real screen height in fullscreen mode? I heard about some kind of hardware profiles, but didn't find any functions which support them.

    Thx for your help,

    Eric

  2. #2
    Registered User
    Join Date
    Aug 2004
    Posts
    33
    Ok, i guess here is the solution for your problem:

    The fullscreen setting takes a while.
    therefore calling getHeight() right after it will get the old data.

    What you have to do is to implement this method in your Canvas Class:

    public void sizeChanged() {
    DISP_HEIGHT = getHeight();
    yOffset = 13 + ((DISP_HEIGHT-208)/2);
    }

    because sizeChanged() is automatically called by the Canvas, if something changes about the size.

    So just replace your public void setHeight()
    with my public void sizeChanged()
    and delete your line
    myCanvas.setHeight();

    Alexander

    Sorry for answering that late.
    I hope it still helps.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    7
    Thanks a lot for your support, I'm gonna try this out.
    I'll tell you later, if it worked

    EDIT: Just tried, didn't work
    Apparently the sizeChanged()-function is not called. Any other idea?

    Have a nice day,

    Eric
    Last edited by teric; 2005-03-30 at 17:10.

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    33
    Hehe

    I'm sorry.
    Here's the real solution:

    protected void sizeChanged(int w,int h) {
    DISP_HEIGHT = h;
    yOffset = 13 + ((DISP_HEIGHT-208)/2);
    }

    Replace my old sizeChanged with this one above.

    Stupid me ;-)

    This one will work.

    Alexander

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    7
    Ok, this works on my Nokia 3230, I'm going to test it on some other devices soon. Thanks again for your support

    As you might have expected, it doesn't work with my emulators

    Greetings,

    Eric



    P.S.: Where did you find this information? I read something about this function, but I didn't find any info about parameters passed.

  6. #6
    Registered User
    Join Date
    Aug 2004
    Posts
    33
    I once had the same problem.
    I found the solution in the Canvas Api.
    Was a little bit hidden. ;-)

  7. #7
    Regular Contributor
    Join Date
    Jul 2005
    Posts
    64
    Here is the solution:

    Just after display.setCurrent stop the main thread for about 200 ms by writing the following statement

    Thread.sleep(200);

    After this you call your setHeight method. Then it will return the height of fullCanvas. Hope this works.....

  8. #8
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    I would not recommend using sleep() in this way, as it is highly non-portable. The correct way is to use the sizeChanged() event as Alexander writes.

    Alternatively, getHeight() in the paint() method every time it is called.

    The problem comes from the fact that the Canvas does not change height immediately, but at some future point. You must wait for an appropriate event (such as sizeChanged() or paint()) before checking getHeight().

    Graham.

Posting Permissions

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