Download presentation
Presentation is loading. Please wait.
1
by Pixer and Didney Animation Studios
How to Animate 101 by Pixer and Didney Animation Studios
2
Compiling, Running, and Quitting
To compile (this will compile any .java files Animate uses): javac -cp objectdraw.jar:. Animate.java To run (this will require all the .class files Animate uses): java -cp objectdraw.jar:. Animate To quit (because the X11 window does not have a close button): Ctrl-C (entered into the terminal)
3
The Basics of Animation
Animation is a series of still images that are shown very quickly To animate something on a computer: Move object to new location Pause for a very short time Repeat steps 1 and 2 The shorter the pause and the smaller the movement, the smoother the animation will be Longer pauses will make the animation seem jerky Making movements bigger or pauses shorter will make the animation faster
4
The Structure of Objectdraw Animation
Two major components: WindowController and Thread Both must be EXTENDED by another class public class Animate extends WindowController {...} public class DrawArc extends Thread {...} The WindowController will create new Threads in the begin() method The animation logic is written in the Thread’s run() method In the files we gave you, Animate is the WindowController, and it creates a new Thread, DrawArc
5
WindowController The driver for all the threads - where all new Threads are created Requires a begin() method, and inside it you want to: Inherit a canvas so the objects know what to draw themselves on DrawingCanvas myCanvas = canvas; Create a new thread and start it, giving them the canvas that we have Thread t1 = new DrawArc(0, 0, myCanvas); t1.start();
6
Animate.java In addition to the standard WindowController methods, Animate has two additional methods catchSleep(): a static function that pauses the program for a few millisections call this in Thread.run() after every movement, otherwise you won’t see the animation because movements happen instantly main(): where the program starts - this is a little confusing because inside of it you create an instance of Animate See slide 8 for clarification of program flow
7
Thread (aka DrawArc.java)
Where the animation actually happens Requires a constructor and a run() method Constructor sets up variables and objects (FilledArc, FilledRect, etc) arc = new FilledArc(..., canvas); //give this the canvas! run() does two things in a loop: Moves your object arc.move(x, y); Pauses the animation so the user can see the progress of the object Animate.catchSleep(milliseconds); You DO NOT call run() anywhere! Run is automatically called by Thread.start(), which you called in Animate
8
ANIMATION.JAVA DRAWARC.JAVA FILLEDARC.JAVA 1. Animation.main() creates a new Animation and runs 3. DrawArc(), which creates other objects by calling 4. FilledArc(), which is the object being moved in DrawArc 2. Animation.begin() creates multiple threads, calling 5. Then starts these threads calling Thread.start(), which automatically calls 6. DrawArc.run(), which loops between first moving the object by calling 8. and then calling 7. FilledArc.move(), which moves this specific object TO PROGRAM YOUR OWN ANIMATIONS, swap out DrawArc.java and FilledArc.java with your own classes and program your own animation logic Ex. MoveSquareUpAndDown.java which uses FilledRect.java 9. Animation.catchSleep() to pause the thread
9
TL;DR Do NOT change Animate.main() or Animate.catchSleep()
Create instances of animations (threads) in Animate.begin(); These are your own animations that EXTEND Thread These require a constructor and a run() method Creation of objects like squares/circles/lines is in constructor Movement/pausing loop happens in run() For a summary of objects you can use - aka circles/squares/lines, look at the left column of this library:
10
GOOD LUCK Albert
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.