This is a discussion on What's the Reason for getHeight() method not return the correct value in Game canvas? within the Mobile Software Development forums, part of the Software Development category; What's the Reason for getHeight() method not return the correct value in Game canvas?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| The main reason for this is that if you call setFulLScreenMode(true) within the constructor of a class - the actual update won’t happen until after the constructor has finished. If you have the calls to getHeight() within the same constructor, or within another constructor in a sequence of class initializations, then it will return the wrong value. Here is one solution (assuming you use a thread for your game loop): 1) Move your call to setFullScreenMode(true); outside of any constructor preferably move it to the startApp() method for your main MIDlet: (e.g.) public void startApp() { if(canvas== null) { canvas = new MyCanvas(this); canvas.setFullScreenMode(true); } Display.getDisplay(this).setCurrent(canvas); canvas.start(); // To start the Thread. } 2) You then need to override the sizeChanged(int w, int h) method of GameCanvas: (e.g) public void sizeChanged(int _w, int _h) { slx = _w; sly = _h; screenUpdated = true; } You will notice here that I am using a Boolean flag to identify whether the screen has been updated or not... 3) In your thread's run() method, inside the while loop, add the following call: while(!screenUpdated) { currentThread.yield(); } This will make your current Thread and wait until the Canvas has been updated and hopefully you will now have the right values |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| The REAL reason we use Linux | JSureshkumar | The Lounge | 8 | 03-17-2008 05:36 AM |
| C is a structural or highlevel or middle level language which one is correct answer | vigneshgets | C and C++ Programming | 3 | 08-25-2007 01:55 PM |
| error (CS1006) when trying to declare a method without specifying a return type | vigneshgets | C# Programming | 1 | 08-01-2007 04:54 AM |
| Is it possible to draw a line over videocontrol in a canvas? | kingmaker | Mobile Software Development | 1 | 07-30-2007 12:58 AM |
| Is there any way to use keyPressed method of Canvas class in Form class? | bluesky | Mobile Software Development | 1 | 07-25-2007 06:02 AM |