You Are Here:

Community: Developer Discussion Boards

#1 Old Unhappy How should a proper game loop be constructed? - 2006-05-05, 08:36

Join Date: Jul 2004
Posts: 16
falconpl
Offline
Registered User
Please explain me where the error is:

I have a main game loop in a run() method of a Thread Object.
It's contents is simple:

Code:
1 switch (gameUtil.getCurrentDisplayNumber())
2   case GameUtil.CANVAS_GAME:
3   {
4      ((Canvas)gameUtil.getCurrentCanvas(GameUtil.CANVAS_GAME)).repaint();
5      ((Canvas)gameUtil.getCurrentCanvas(GameUtil.CANVAS_GAME)).serviceRepaints();
6      break;
7   }
8   case GameUtil.CANVAS_GAME_OVER:
9   {
10      ((Canvas)gameUtil.getCurrentCanvas(GameUtil.CANVAS_GAME_OVER)).repaint();
11      ((Canvas)gameUtil.getCurrentCanvas(GameUtil.CANVAS_GAME_OVER)).serviceRepaints();
12      break;
13  }
The main game logic is inside the paint method of the game canvas.
I utilize the fact that paint() is called all the time and I do all movement calculations
inside this method.

Now, when somewhere inside this paint() method I detect that the player has lost all lives
I want to switch to a Game Over screen. So I call:

Code:
gameUtil.setCurrentDisplayNumber(GameUtil.CANVAS_GAME_OVER);
Display.getDisplay(gameUtil.getGameMIDlet()).setCurrent(gameUtil.getCurrentCanvas(gameUtil.getDisplayNumber()));
This call is made somewhere inside the paint() method of the game canvas.

And the problem is that on some phones the game over canvas shows up but is deadlocked.
I mean the paint() method of the game over canvas is called only once and never again.

I noticed that removing the serviceRepaints() call from the 5th line solves the problem but
it result in animation frames being dropped (at least it looks like this).

So I want to find out what is causing the problem - what I'm doing wrong and how to correct it.
Reply With Quote

#2 Old Re: How should a proper game loop be constructed? - 2006-05-06, 01:16

Join Date: Jul 2004
Posts: 16
falconpl
Offline
Registered User
I moved the game logic out of the paint() method and now use the latter only for painting and everything is OK now.
Reply With Quote

#3 Old Re: How should a proper game loop be constructed? - 2006-05-08, 12:36

Join Date: Feb 2006
Posts: 689
soku123
Offline
Super Contributor
Hi,
please dont use any code that is used for calculation inside the paint method.It will cause serious probleems.
Regards
Soku
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Great game Wappo geonofear News, Announcements and Job Listings 2 2007-01-03 13:00
Main loop of MIDP2 game? pachura Mobile Java General 1 2006-03-07 10:16
RunL() method is not being called dotcdotc General Symbian C++ 9 2004-12-13 12:25
Best game loop approach? marcpalmer Mobile Java General 1 2003-09-01 11:26
Game loop question tinkezione Mobile Java General 7 2002-12-31 09:14

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d127641X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZgamesQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ