Graphical Objects + Animation = Sprites
Methods of Animation
Using the Timer Class
Using Infinite Loop Animation
- Example - Hello World with an Infinite loop and delay loop (source code)
Advantages:
- Simple to understand
- Compatible with anything
Disadvantages:
- Doesn't allow simultaneous action
- Speed varies vastly by computer and by other usage of CPU
- CPU time completely used up - often freezes the computer completely.
Using Runnable- the ultimate interface for animation
Flicker/speed- to repaint() or not to repaint()
repainting
Examples:
Advantages to repainting:
- Easy to do
built in refreshing/undrawing of previous frame
- Speed
Disadvantages of repainting
Not repainting
Advantages of not using repaint():
Disadvantages of not using repaint():
- No built in redrawing- Example (source)
- Therefore, you have to manually 'undraw' or overdraw each sprite. This can cause problems, as well: Example (source)
- This can make it slow down slightly
- Note: Since my example is dependant on fonts, if you have font smoothing turned on (in your display settings), the letters will leave "trails" as they move around.
Image Buffering
(Image buffering is putting together an image off the screen and then displaying it all at once)
Advantages of image buffering
- Sprite refreshing is unnecessary, so sprites can pass over each other with out undrawing over each other
Disadvantages of image buffering
- Creating the image can take more time than drawing on to the canvas, so animation goes slower
- The number 1 reason to use image buffering is so that you can use background images and have the sprites pass over the background flawlessly
|