Author |
Message |
nonamedude
|
Posted: Sat May 15, 2010 11:11 am Post subject: Animating an object |
|
|
I am just wondering how to animate a shape for example a circle (maybe falling down vertically until it reaches a certain location) in applets.
--------------
Maybe I should rephrase my question
For example in a game; objects move across the screen. How would you achieve this in java?
I want to move a circle from the top of the screen to the bottom.
I am using Ready to program (I have to use this :/ ) and i am making an applet |
|
|
|
|
|
Sponsor Sponsor
|
|
|
nonamedude
|
Posted: Mon May 24, 2010 8:36 pm Post subject: Re: Animating an object |
|
|
~Bump~ |
|
|
|
|
|
Tony
|
Posted: Mon May 24, 2010 9:13 pm Post subject: RE:Animating an object |
|
|
Animation is the process of drawing something at progressing locations. Once at the start, once a few pixels down... Essentially you'll be drawing various animation frames (think movie reels); and if they are drawn fast enough, it all blends smoothly into an animation. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
nonamedude
|
Posted: Mon May 24, 2010 9:29 pm Post subject: Re: Animating an object |
|
|
So would you use a for loop and draw the circle at locations that progressively gets higher or lower? |
|
|
|
|
|
Tony
|
Posted: Mon May 24, 2010 9:39 pm Post subject: RE:Animating an object |
|
|
That is the very basic demonstration of the concept, yes!
The next question that many run into shortly after -- what if I have two circles on the screen? If you have two for-loops, then the 2nd circle must wait for the first for-loop to complete. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
nonamedude
|
Posted: Tue May 25, 2010 8:48 pm Post subject: Re: Animating an object |
|
|
oh ...
so wait
if i do this the screen would flicker every time a new circle is created. And another problem would be; how to delete the circles created from the loop |
|
|
|
|
|
TheGuardian001
|
Posted: Tue May 25, 2010 11:06 pm Post subject: Re: Animating an object |
|
|
Flickering generally shouldn't be a problem for simple animations (it will be a problem later on, but solving that problem can wait at least a little while). Clearing can be done using the g.clearRect() method.
Where you will run into problems, if you use for loops, is having more than one object move at the same time. Since only one for loop can be running at a time, one object must finish moving completely before the other can start. You have to find a way to have two objects appear to move together.
If you are interested in flicker free drawing, you will need to create both your own Image object and your own Graphics object, in order to achieve a double buffering effect (I'll go into detail if this actually becomes a problem for you) |
|
|
|
|
|
nonamedude
|
Posted: Thu May 27, 2010 10:59 pm Post subject: Re: Animating an object |
|
|
Oh.... ty a lot, the basics seem sufficient for my project so i'll stick with that. Ty for ur help guys |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|