Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 10:19, 28 November 2007.

How to make an animation loop

From Forum Nokia Wiki

If you need to make some animation in Java ME Canvas, you must use a Game Loop using multithreading.

This code will be useful as a template for doing such animation.

class MyAnimation extends Canvas implements Runnable {
 
   private Thread thread;
   private boolean executing;
   private final int SLEEP = 200;
 
   public void start() {
      executing=true;
      thread = new Thread(this);
      thread.start();
   }
 
   public void stop() {
       executing = false;
   }
 
   public void run() {
      // Do some initial action
      while (executing) {
         // move objects or sprites to the next animation frame
         repaint();
         serviceRepaints();//repaint is a just a request whereas 
                           //servicerepaint is a command to repaint all 
                           //ur pending repaint requests
      }
      try {
         // Send the thread to "sleep" for a couple of milliseconds
         Thread.sleep(SLEEP);
      } catch(Exception e) {} 
   }
 
   public void paint() {
       // Draw objects on screen
   }
}
Related Discussions
Thread Thread Starter Forum Replies Last Post
starting out with graphics sunny__l Mobile Java Media (Graphics & Sounds) 1 2003-12-06 22:33
exiting a loop / loop and thread. adamzieba Mobile Java General 1 2007-08-04 15:15
Data Input Stream Problem marquix Mobile Java General 4 2007-01-25 05:07
Nokia 6233 fade out stops animations aldebaran2 Series 40 & S60 Platform Feedback 0 2006-11-20 14:58
How To Create Animated Background Using Carbide.ui 3.1?? chenloong Themes/Carbide.ui 3 2007-10-24 09:43
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZanimationQ
     qfnZtopicQUqfnTopicZjavaQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX