1 / 21

Events

Events. Chapter 7. Interactive. Real world is interactive User determines order of actions instead of programmer. Control of Flow. How sequence of actions in program is controlled What action happens first, next, and so on Animations

hova
Télécharger la présentation

Events

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Events Chapter 7

  2. Interactive • Real world is interactive • User determines order of actions instead of programmer

  3. Control of Flow • How sequence of actions in program is controlled • What action happens first, next, and so on • Animations • Movie-style - programmer determines sequence of actions prior program running • Interactive - sequence of actions determined at runtime by user

  4. Event • Program reacts to • Mouse click • Key press on keyboard • Changes that occur during program execution • Control of flow is now controlled by user

  5. Events • Each time user provides some sort of input, we say an eventis generated • An event is “something that happens” • An event may • Trigger a response • Move objects into positions that create a condition that triggers a response • Ex: A collision that moves objects

  6. Event Handler Method • Called when event occurs • Called behavior • Linked to event in Event editor • Behavior – when method linked to event is performed due to an action

  7. Creating An Event Click on create new event in Events window

  8. 6.1 Alice Events • When the world starts • When a key is typed • When the mouse is clicked on something • While something is true • When a variable changes • Let the mouse move <object> • Let the arrow keys move <subject> • let the mouse move the camera • Let the mouse orient the camera • See Table 7-1 on page 272 for details of each

  9. 6.1 Specialized Events • Some events from the previous list do not appear in the Events Editor • While a key is pressed • While the mouse is pressed on something • While the world is running • When something becomes true • To create specialized event • Create general event • Right-click and select change to

  10. 6.2 Key Press Event • Alice can detect when a key on keyboard is pressed • Event is triggered when the user types a key • Key that will trigger the event must be specified • any key is the placeholder until you choose a specific key • Can have event activated when any key is pressed • Click on Nothing • Choose custom method from drop down menu

  11. Tutorial 7-1: Key Press Event • Have each fairy flap her wings and move up and down when a key is pressed called fly • When G is pressed event to cause Gossamer to fly • When M is pressed event to cause Hazelnut to fly

  12. Storyboards Event: G key is pressed Response: Do together Flap wings of Gossamer Move Gossamer up ½ meter Do together Flap wings of Gossamer Move Gossamer down ½ meter Event: M key is pressed Response: Do together Flap wings of Hazelnut Move Hazelnut up ½ meter Do together Flap wings of Hazelnut Move Hazelnut down ½ meter

  13. Programs for Faeries Flying Both events can run at same time

  14. Mouse Event • Interactive programs often allow the user to use a mouse to click • Examples • Buttons in a windows-based interface • Choose targets in a game • Select items in checklist on a form

  15. 6.2 Creating Mouse Event • Event is triggered when the mouse is clicked on an object in the world • Click on create new event and choose When the mouse is clicked on something • It can be • Anything • Any object in the Alice World • Choose event handler by clicking on nothing

  16. Tutorial 7-3: Mouse Event • Click on refrigerator door causes door to open • Can place Alice statement directly in event declaration

  17. Fridge Door Opens and Closes • To get door to open and close you need to remember the state of the door • Is it open or closed? • Use boolean variable: doorOpen • If doorOpen = true then door is open • Close door • Set doorOpen to false • If doorOpen = false then door is closed • Open door • Set doorOpen to true

  18. Storyboard Event: Mouse clicked on fridge door Response: If doorOpen = true Turn door right ¼ revolution doorOpen = false Else Turn door left ¼ revolution doorOpen = true

  19. Program to Open and Close Door

  20. Create Your Own People Models • Use hebuilder and shebuilder • In People gallery • Choose all features of person • Has built-in methods • hello, angry, happy, walk, confused, no, yes

  21. Homework • Read chapter 6 sections 1 and 2 • Answer questions in handout • Do lab assignments after handing in answered questions • Due one week after assigned with 1 week grace

More Related