- Forward


Basics of Computer Animation
in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Definitions
Back SMYC Forward
  • Animate:
    • To give life or motion
  • Animation:
    • A group of techniques that can make visual content appear to move
Techniques to Consider
Back SMYC Forward
  • Sampled Dynamics (a.k.a. Frame Animation)
  • Described Dynamics (a.k.a. Sprite Animation)
Sampling Dynamic Visual Content
Back SMYC Forward

An Illustration

images/dynamic-sampling.gif
Terminology for Sampled Dynamics
Back SMYC Forward
  • Frame Rate:
    • The number of frames per unit time
  • Animate:
    • To give life or motion
  • Frame Animation:
    • The "play back" of sampled dynamic visual content
Some Observations
Back SMYC Forward
  • Each frame is thought of as a coherent whole
  • Each frame consists of static visual content
  • Each frame can be either sampled or described (and is completely independent of the time-based sampling)
Describing Dynamic Visual Content
Back SMYC Forward
  • The Concept:
    • Describe the way the visual "stream" changes over time
    • Start with a set of components (i.e., the "participants" in the "action") and then describe component-by-component changes
  • Analogy:
    • A play with a script, stage directions, actors, sets, and a stage
Terminology for Described Dynamics
Back SMYC Forward
  • Sprite:
    • Common Usage - an imaginary being or elf
    • Animation - a discrete piece of visual content that can respond to descriptions of changes
  • Stage:
    • The "component" that sprites act "on"
What's Involved?
Back SMYC Forward
  • A Timer object that sends actionPerformed() messages
  • An ActionListener on the Timer that updates state information each "tick"
  • A JComponent that renders itself using the state information
A Simple Example
Back SMYC Forward

An Animated Rectangle

javaexamples/multimedia/AnimatedRectangle.java
 
Another Simple Example
Back SMYC Forward

An Animated Curve

javaexamples/multimedia/AnimatedCurve.java
 
User Interaction
Back SMYC Forward
  • Mouse Events:
    • A JComponent can have both MouseListener java.awt.event.MouseListener and MouseMotionListener java.awt.event.MouseMotionListener objects
  • Keyboard Events:
    • A JComponent can have KeyListener java.awt.event.KeyListener objects
An Example of User Interaction
Back SMYC Forward

Whack-A-Duke

javaexamples/multimedia/WhackADuke.java
 
A More Object-Oriented Example
Back SMYC Forward

A Fish Class

javaexamples/multimedia/Fish.java
 
A More Object-Oriented Example (cont.)
Back SMYC Forward

The FishTank

javaexamples/multimedia/FishTank.java
 
There's Always More to Learn
Back -