You Are Here:

Community: Wiki

This page was last modified on 5 June 2009, at 10:46.

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 Wiki Articles

No related wiki articles found

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: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fM2GX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZanimationQ qfnZtopicQUqfnTopicZgraphicsQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ