| Reply | « Previous Thread | Next Thread » |
|
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 |
|
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. ;) |
|
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 18:10.
|
|
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 |
|
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. |
|
I once had the same problem.
I found the solution in the Canvas Api. Was a little bit hidden. ;-) |
|
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..... |
| pankaj_hotwani |
| View Public Profile |
| Find all posts by pankaj_hotwani |
|
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. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|