Results 1 to 5 of 5
Thread: Delaying Animation
- 08-24-2012, 03:51 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 28
- Rep Power
- 0
-
Re: Delaying Animation
You could slow down the animation loop. How you do this will depend almost completely on how you are currently animating.
- 08-24-2012, 03:53 AM #3
Member
- Join Date
- Aug 2012
- Posts
- 28
- Rep Power
- 0
Re: Delaying Animation
heres what I have so far but the delay method isnt really working
Java Code:import java.awt.*; import java.applet.Applet; public class Liang extends Applet { public void paint( Graphics screen ) { setBackground( Color.green ); Image hare = getImage( getDocumentBase(), "hare.gif" ); Image tortoise = getImage( getDocumentBase(), "tortoise.gif" ); screen.drawImage( hare, 5, 5, this); screen.drawImage(tortoise, 5, 120, this); screen.drawLine( 0, 115, 1300, 115); int disfromfinh = 50; int disfromfint = 50; int xh = 5; int xt = 5; while ( disfromfinh > 0 & disfromfint > 0 ) { // For the hare int moveh = (int)(Math.random() * 10) + 1; if (moveh == 1 | moveh == 2) { delay();delay();delay(); screen.clearRect(xh, 5, xh + 118, 107); int a1 = xh + 180; screen.drawImage( hare, a1 , 5, this); xh = a1; disfromfinh -= 9; } else if (moveh == 3 | moveh == 4 | moveh == 5) { delay();delay();delay(); screen.clearRect(xh, 5, xh + 118, 107); int a1 = xh + 20; screen.drawImage( hare, a1 , 5, this); xh = a1; disfromfinh -= 1; } else if (moveh == 6) { delay();delay();delay(); screen.clearRect(xh, 5, xh + 118, 107); int a1 = xh - 240; screen.drawImage( hare, a1 , 5, this); xh = a1; disfromfinh += 12; if (disfromfinh > 50) { screen.clearRect(xh, 5, xh + 118, 107); screen.drawImage( hare, 5 , 5, this); disfromfinh = 50; xh = 5; } } else if (moveh == 7 | moveh == 8) { delay();delay();delay(); screen.clearRect(xh, 5, xh + 118, 107); int a1 = xh - 40; screen.drawImage( hare, a1 , 5, this); xh = a1; disfromfinh += 2; if (disfromfinh > 50) { screen.clearRect(xh, 5, xh + 118, 107); screen.drawImage( hare, 5 , 5, this); disfromfinh = 50; xh = 5; } } else screen.clearRect(xh, 5, xh + 118, 107); delay();delay();delay(); disfromfinh = disfromfinh; //For the turtle int movet = (int)(Math.random() * 10) + 1; if (5 >= movet & movet >= 1) { screen.clearRect(xt, 120, xt + 130, 198); delay();delay();delay(); int a2 = xt + 60; screen.drawImage( tortoise, a2 , 120, this); xt = a2; disfromfint -= 3; } else if (movet == 6 | movet == 7 | movet == 8) { screen.clearRect(xt, 120, xt + 130, 208); delay();delay();delay(); int a2 = xt + 20; screen.drawImage( tortoise, a2 , 120, this); xt = a2; disfromfint -= 1; } else { screen.clearRect(xt, 120, xt + 130, 208); delay();delay();delay(); int a2 = xt - 120; screen.drawImage( tortoise, a2 , 120, this); xt = a2; disfromfint += 6; if (disfromfint > 50) { screen.clearRect(xt, 120, xt + 130, 208); screen.drawImage( tortoise, 5 , 120, this); disfromfint = 50; xt = 5; } } } } public void delay() { for( int i = 0; i <= 900000000; i++ ); } }
-
Re: Delaying Animation
Step back a bit and first fix your non-animation drawing code as you're doing a lot incorrectly starting with setting a background color. This is not done in the paint method itself. Next you appear to have program logic in the paint method -- another thing that you should never do. Next you seem to have your animation itself in the paint method, another thing you should never do.
I suggest that you go through some of the painting/drawing tutorials first to learn some of the rudiments of Java painting. Next consider using Swing rather than AWT. Then do your animation with a Swing Timer. Then you could delay the animation simply by increasing the Timer's delay property setting.
- 08-24-2012, 03:59 AM #5
Member
- Join Date
- Aug 2012
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Animation with Animated GIF
By JavaBean in forum Java 2DReplies: 3Last Post: 06-04-2011, 04:26 PM -
Animation
By ryainad in forum Advanced JavaReplies: 1Last Post: 04-04-2011, 05:52 PM -
program not delaying
By Brain_Child in forum New To JavaReplies: 2Last Post: 11-29-2009, 02:10 PM -
need help about animation ?
By h9h in forum Java 2DReplies: 1Last Post: 10-30-2009, 11:41 AM -
GUI Animation
By serfster in forum New To JavaReplies: 2Last Post: 06-11-2008, 03:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks