EVENT HANDLING Scene ActivationTime Keyboard controls Mouse controls
EVENT HANDLING Scene Activation/Time Keyboard controls Mouse controls Position/Orientation
User Input to Reposition Objects at Run. Time To create an interactive program, a Listener object must be added to the scene. The add. Default. Model. Manipulation procedure creates a Listener object that targets a mouseclick on any object in the scene and responds by allowing the user to drag that object around the scene while the animation is running.
(1) Add the add. Default. Model. Manipulation Procedure 1. Add Event Listener. 2. Select the add. Default. Model. Manipulation procedure under Mouse.
(2) Steps to Add the add. Default. Model. Manipulation Procedure 1. Go to the Scene tab. 2. Drag the add. Default. Model. Manipulation procedure (Scene class) into the initalize. Event. Listeners Code editor.
Using the add. Default. Model. Manipulation Procedure This procedure allows you to reposition objects at runtime: • Click and drag the object with your cursor to move it around the scene.
Using the add. Default. Model. Manipulation Procedure This procedure allows you to reposition objects at runtime: • Press the Control (Ctrl) key, and then click and drag the object with your cursor to turn it right and left. • Press the Shift key, and then click and drag the object to move it up and down.
Lecture Practice #11 Create a. docx file with your name, the date, and your class (CMSC 100) in the upper right corner. “Lecture Practice #10” should be centered. Name the file as follows: <your blackboard username>_ Lecture. Practice 11. docx When you have completed all the tasks, upload your. docx file to the blackboard website under Lecture Practice 11 Task #1 – Create an Alice world with the sea floor. Place several types of fish, sharks, etc. in the world. Add the add. Default. Mode. Manipulation Procedure to the initialize. Event. Listeners. Take a screenshot of your initialize. Event. Listeners and paste it into the. docx file with the heading Task #1.
add. Mouse. Click. On. Object Listener If you want something to happen when you click on an object in the scene, you will need to use the add. Mouse. Click. On. Object Listener.
add. Mouse. Click. On. Object Listener 1. Place a if statement in the mouse. Clicked procedure. You will need to build a relational statement to determine which object has been selected. Select shark and shark.
add. Mouse. Click. On. Object Listener 2. Drag the get. Model. At. Mouse. Location into the this location.
add. Mouse. Click. On. Object Listener 3. Place in the code for what you want to have happen when the shark is selected
Lecture Practice #11 Task #2 – Create an event that has all the other fish turn to face the shark when you click on the shark. Comment your code. Run the animation and make sure it is working correctly. Take a screenshot of your mouse. Clicked procedure and paste it into the. docx file with the heading Task #2.
Lecture Practice #11 Task #3 – Create an event that has everything except the shark do something when you click on it (turn in a circle, flap their fins, etc. ). Comment your code. Run the animation and make sure it is working correctly. Take a screenshot of your mouse. Clicked procedure and paste it into the. docx file with the heading Task #3.
Good to Know When the program starts, the scene can "listen" for events. That's why the my. First. Method starts. If your scene doesn't appear to be "listening" it is because the Run window is not the active window. Click on the scene in the Run window, to make it active.
Position/Orientation Listeners We are going to look at the listeners for detecting if there is a collision between two objects
add. Collision. Start. Listener 1. Select the add. Collision. Start. Listener from the Position/Orientation Event Listeners
add. Collision. Start. Listener 2. The first argument is an array that contains the objects that may initiate a collision. 3. The second argument is an array of objects that when colliding with the first array should be handled. 4. You can select Custom Array to create the array of objects on the fly.
add. Collision. Start. Listener Our shark is hungry and wants to “eat” some of the other fish in the ocean. We want to detect a collision between the shark and the other fish and then have that fish disappear. The first array is going to be just the shark, and the second array is going to be all the other fish
add. Collision. Start. Listener Now we need to determine which object in the second array that the shark collided with, so that they can “disappear” Use an if statement to check which object it is. Drag the “gets. Things. From. Set. B” into the condition for the if statement and one of the objects from the second array – in this case we are going to create the statement to make the Orca disappear when the shark collides with it.
Lecture Practice #11 Task #4 – Create a Default. Model. Manipulation Listener which will allow you to move the “swimmers” around the screen. Create a add. Collision. Start. Listener where the shark is in the first array and the other “swimmers” are in the second array. When the shark collides with any of the other swimmers, have that swimmer disappear and the shark says “Yum”. Take a screenshot of your collision. Started procedure and paste it into the. docx file with the heading Task #4. This is a partial solution – only for the Orca
- Slides: 20