AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

smooth animation

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Mike Crenshaw
Guest





PostPosted: Tue Sep 28, 2004 4:06 pm    Post subject: smooth animation Reply with quote



Hi

I'm trying to figure out how to make an animation move smoothly.. so i've
been looking around.. i've found 3 other methods besides just using sleep()
at each frame.. i've tried implementing these methods but i cant see much of
a difference.. but which of the following, if any, is the best way to go
about it.. or is there a better way..

method 1: the nono
...
while(true){
x++; //some simple movement
y++;
paint(getGraphics());
try{
Thread.currentThread().sleep(delay);
}
catch(Exception e){}
}

method 2:
....
while(true){
long start = System.currentTimeMillis();
x++; //some simple movement
y++;
paint(getGraphics());
try {
Thread.sleep(Math.max(0, (start + delay) -
System.currentTimeMillis()));
}
catch (InterruptedException e) {};
}

method 3:
....
while(true){
long start = System.currentTimeMillis();
x++; //some simple movement
y++;
paint(getGraphics());
long sleepTime = delay - (System.currentTimeMillis() - start);
if (sleepTime > 0)
try{
Thread.currentThread().sleep(sleepTime);
}
catch(Exception e){}
}

method 4: frame independent

int velocity = 500;
long end_time = 0;
long start_time = System.currentTimeMillis();
float elapsed_time = 0;
float dtime = 0;
while(true){
end_time = System.currentTimeMillis();
elapsed_time = end_time - start_time ;
dtime = elapsed_time / 1000 ;
x += dtime * velocity; //some simple movement
y += dtime * velocity;
start_time = System.currentTimeMillis();
paint(getGraphics());
try{
Thread.currentThread().sleep(delay);
}
catch(Exception e){}
}

thanx
mike


Back to top
Paul Lutus
Guest





PostPosted: Tue Sep 28, 2004 4:50 pm    Post subject: Re: smooth animation Reply with quote



Mike Crenshaw wrote:

Quote:
Hi

I'm trying to figure out how to make an animation move smoothly.. so i've
been looking around..

Define "move smoothly". How many frames per second do you require? How large
is the animated frame? What is the color depth? What is the target
environment? What is the expected target platform's clock speed?

Define "looking around". Which painting methods have you tried?

Quote:
i've found 3 other methods besides just using
sleep() at each frame.. i've tried implementing these methods but i cant
see much of a difference.. but which of the following, if any, is the best
way to go about it.. or is there a better way..

The "better way" is the one that delivers what you want, which you don't
specify. You don't specify what is being drawn, how it is being drawn, or
provide a working code example.

--
Paul Lutus
http://www.arachnoid.com


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.