Download presentation
1
Interaction: Events and Event Handling
Chapter 5 - Alice Interaction: Events and Event Handling
2
Interactive Program –vs- Non-Interactive Program What is the main difference?
The sequence of actions is determined at runtime! Occurs when: The user clicks the mouse Presses a key on the keyboard Objects in the scene move (randomly or guided by the user) User can create some conditions like a collision. Non-Interactive The sequence of actions is pre-determined by programmer Programmer designs a complete storyboard Programmer writes the program code for the animated actions. Every time the program runs the same sequence will occur.
3
What is an Event? An event is something that happens.
Every time the user clicks the mouse or presses a key on the keyboard to send a signal to Alice about what to do next. The mouse click or key press is an event! In this chapter we learn the mechanics of how the user create an event and how the program responds to the event. Example: think of a video game – A Car Race. The scene is determined on how skillful the driver is steering the car.
4
Event handling method! How does it affect what I do?
As a animation programmer you must think about all possible events and make plans for what should happen. You need to response to the events. Remember: When the event handling method occurs, the location of objects in the scene may or may not be the same as the last time.
5
Biplane Example: Is an interactive program!
Biplane is in mid-air and the user is able to fly the plane. The plane can move forward, left, and right and a barrel turn. The user uses the keyboard and mouse to provide interaction. The whole idea is to let the user interact with the biplane.
6
Biplane Example: Has two events:
The spacebar press for the barrel turn and the up arrow key to move the biplane forward. Event: Spacebar Response: Do together roll biplane a full revolution Play biplane engine sound Event: Up arrow key press Response: Do together move biplane forward play biplane egine sound Page 122 to Just follow the steps.
7
Testing! How to test? Just save the world and press the PLAY button.
Tip: It is important to test event handling methods as they are developed. Write a method and test it, write a method and test it, until the program is completed. Why? Incremental development! The advantage is in making it easier to debug your program. When something isn’t working, it can easily be fix before it causes bigger problems elsewhere in your program.
8
Parameters and event handling methods:
Parameters are powerful! They allow us to customize methods to work with different objects and different numeric values. Take a look at the Firetruck/Burning Building example. (page 125 to 127, just follow the steps)
9
Burning Building Example:
Another interactive program that shows how to use parameters in event handling methods. Firetruck is called to a burning building. The truck will need to extend its ladder so that each person can climb down to safety.
10
Burning Building Example:
Three Events are: Event: Click on guy1 Responding Method: Save guy on the first floor Event: Click on girl2 Responding Method: Save girl on the second floor Event: Click on girl3 Responding Method: Save girl on the third floor Are all these events necessary? Why three? Can we do the same in one event?
11
Burning Building Example:
A better solution is to write only one event and send the information to the action. Look: savePerson Parameters: whichFloor, whichPerson, howFar Do in order: Point ladder at whichFloor Extend the ladder howFar meters whichPerson slides down the ladder to the firetruck Pull the ladder back howFar meters Take a look at the program. Follow the steps on page 125 to 127
12
For Today: Read chapter 5! Take notes for yourself. (You can use them on the test) Complete the worksheet questions. You have 5 of them! Answers in Chapter 5. Finish with the examples in Chapter 5. Last chance if you want credit. Plane Program – Page 121 to 124 Burning Building – Page 125 to 127 Page 139, #12 Snow Festival.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.