IT Community - Software Programming, Web Development and Technical Support

What's the Reason for getHeight() method not return the correct value in Game canvas?

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?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Mobile Software Development

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-18-2007, 10:25 PM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Question What's the Reason for getHeight() method not return the correct value in Game canvas?

What's the Reason for getHeight() method not return the correct value in Game canvas?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-19-2007, 01:06 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: What's the Reason for getHeight() method not return the correct value in Game can

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 12:27 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0