Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (686)
Games in Android Showcase (198)
games submitted by our members
Games in WIP (758)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  thread vs. timer/timerTask  (Read 1938 times)
0 Members and 1 Guest are viewing this topic.
Offline frustr8ed

Junior Newbie

Java games rock!

« Posted 2005-02-03 00:00:22 »

hello. im currently developing an rpg. just want to ask if its ok to use a timer to control my game loop rather than thread. my application is doing well with this timer but it hangs sometimes. i wonder if the timer has something to do with this.   Huh i tried to convert the timer into thread but my application doesn't work the way i wanted. please help. thanks  Cry
Offline ribot

Junior Devvie

Ribot - mobile UI specialist

« Reply #1 - Posted 2005-02-03 21:39:17 »

What do you mean by 'doesn't run the same way'? I'm not sure of the exact performance comparison, but I would have thought that the thread would be a far more efficient method for running game logic and painting?  How many frames per second are you getting/need?  What type of canvas are you extending?  Have you tried implementing your game using a thread architecture combined with a GameCanvas (MIDP2.0)?

Also, do you have any screen shots of the current implementation?


Ribot - design agency focused on mobile - online vintage eyewear store
Offline frustr8ed

Junior Newbie

Java games rock!

« Reply #2 - Posted 2005-02-04 00:14:46 »

when i converted the timer into a thread, the thread stops/hangs when i press a key. i tried to put the keyPress method inside the run() but it doesn't work still. i have at at most 5 frames for player's walking,'s walking, attacking etc. I extended the GameCanvas and tried to implement Runnable.  :-/

I've seen most of the mobile games are implemented and have their game loop using thread. i wonder if it's ok to use timers instead.  Huh
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davidaprice

Junior Devvie

« Reply #3 - Posted 2005-02-04 07:18:19 »

Timers just use Threads anyway, so there shouldn't be much difference in performance except for maybe a very slight overhead cost for the code in the Timer methods.

Have you checked out Forum Nokia's MIDP 2.0 Game API example, the Sheepdog game? It uses GameCanvas and Threads, and doesn't hang. You could download its source code and compare with what you're doing. If you have any questions about its design, you could ask here: I'm the author of that example (and the voice of the sheep!).

Offline ribot

Junior Devvie

Ribot - mobile UI specialist

« Reply #4 - Posted 2005-02-04 11:44:47 »

I get very smooth animation when using a GameCanvas plus thread.  The run method of my thread looks something like this:

while(isRunning) {
  tick();  // logic code - tick the controller.
  if(isShown) {
    if(!isPainting) {

  try {
  } catch (Exception ex) {}

Were you getting the pauses when testing on the device as well as the emulator.  Also, what are your methods that keyPressed() calls doing?  Sounds like your doing something intensive, which shouldn't be in a keypress.


ribot - design agency focused on mobile - online vintage eyewear store
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

roseslayer (503 views)
2016-08-06 11:43:29

roseslayer (461 views)
2016-08-06 09:43:11

xTheGamerCodes (534 views)
2016-08-04 15:40:59

xTheGamerCodes (528 views)
2016-08-04 15:40:24

orrenravid (874 views)
2016-07-16 03:57:23

theagentd (953 views)
2016-07-11 14:28:54

Hydroque (1049 views)
2016-07-06 05:56:57

Hydroque (1034 views)
2016-07-03 08:52:54

GrandCastle (849 views)
2016-07-01 09:13:47

GrandCastle (643 views)
2016-07-01 09:09:45
Rendering resources
by Roquen
2016-08-08 05:55:21

Rendering resources
by Roquen
2016-08-08 05:52:42

Rendering resources
by Roquen
2016-08-08 05:50:38

Rendering resources
by Roquen
2016-08-08 05:49:53

Rendering resources
by Roquen
2016-08-08 05:32:39

Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!