Animations |
We talked about creating animations, including a rather "pathetic" version of the pong game.
These examples involve creating classes using the Animation library.
Our first simple example is of a falling ball in a window with a Pong paddle. The Pong paddle can move at the same time that the ball falls. The main event thread handles the mouse motion methods (e.g., onMouseMove). To do something else at the same time we must use the Animator library.
That library has methods while{b:Boolean}pausing(delay:Number)do{stuff:Done} and whileb:Booleanpausing(delay:Number)dostuff:Donefinally{ endStuff }.
Let's look at the first one. If we write while {cond} pausing(delay) do {stuff} then we get a loop like a regular loop while {cond} do {stuff} with the difference that there is a pause of delay milliseconds between executions of stuff. When your program starts executing this while loop, the code after the loop will execute, even though the loop is not done. Essentially we want this loop to be run at the same time as other stuff is being done by your program.
The second is very similar. However, when the loop terminates, it will execute the block of code in the finally clause. Remember that the rest of the program has been executing while this loop has been running. Hence if this material was put immediately after the while loop (but not in a finally clause) then it likely would be run before the loop finishes.
Actually, we will consider a definition of a moving Pong ball that just falls rather than bouncing off the walls or paddle. The main program that controls it is also available. This makes for a pretty boring pong game, but it does demonstrate the basics of ActiveObjects.
Animations |