Download presentation
Presentation is loading. Please wait.
Published byYazmin Ledbetter Modified over 9 years ago
1
Class-level Methods Chapter 6
2
Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class level object Examples o A person walking o A skater skating Unlike world class-level methods o Which has access to multiple classes
3
Example Skater object does not have a skate method To create a skate method for ice skater objects We need to: (1)Tell Alice to associate a new method with iceSkater class (2)Write a new method to animate ice skater skating
4
Associate Animation with Skater Select iceSkater tile in Object Tree Select methods tab in details panel Click on create new method button
5
Storyboard for skate Method The slide actions each require several motion instructions Break down these two actions into smaller steps skate: Do together move skater forward 2 meters Do in order slide on left leg slide on right leg
6
Stepwise Refinement Refinement of slideLeft Do in order Lift right leg and turn upper body forward Lower right leg and return body upright Skate: Do together 1) move forward 2 meters 2) Do in order slideLeft slideRight Refinement of slideRight Do in order Lift left leg and turn upper body forward Lower left leg and return body upright
7
Demonstration Concepts illustrated o Method defined for a specific type of object defines action for that object o A method can call other methods skate method calls slideRight and slideLeft
8
Reuse Writing methods that make ice skater perform skating motion is complex task Would like to reuse iceSkater skate in other worlds without writing methods again
9
Creating A New Class 1)Rename iceSkater as cleverSkater either a)Double click object name b)Or right click name 2)Right click name to save as a new class 3)Alice saves new class as CleverSkater.a2c Alice v2 Class
10
Inheritance The CleverSkater class o Inherits all properties and methods from original IceSkater class o Has newly defined methods skate, slideLeft, slideRight In other programming languages o Inheritance - creates new class based on previously defined class
11
Importing CleverSkater An instance of the CleverSkater class can be added to a new world o Use File | Import o Set File Type to A2C o Choose class to import
12
Interacting With Other Objects Suppose you want to write a class-level method where another object is involved? Ex: method to make skater skate around another object, the penguin in this scene
13
Parameters in Class-level Method Solve skate around object by writing a class-level method with an object parameter Allows you to pass a specific object cleverSkater.skateAround Parameter: whichObject Do in order Do together cleverSkater turn to face whichObject cleverSkater lift right leg cleverSkater move to whichObject cleverSkater turn around whichObject
14
Guidelines To avoid potential misuse of class-level methods follow these guidelines o Avoid references to other objects Use parameters if referencing another object is required o Avoid calls to world-level methods Will not be saved with new class you created o Play a sound only if sound has been imported and saved out as part of new class
15
Demonstration Concept illustrated o Parameter whichObject is placeholder for the object value passed to it Ex: penguin
16
Class-Level Variables as Properties Property is a variable that belongs to an object Properties can be added to an object through the creation of class-level variables When the object is saved as a new class the variables are saved with it Common properties are: o color o opacity o isShowing
17
Tutorial 6-5: Turn Monitor On/Off Create class-level variable that keeps track of state of computer monitor: on or off On Off
18
Storyboard turnOnOff Do in order If monitor is on set screen color to black is on set to false Else set screen color to no color isOn set to true Endif
19
Storyboard Translated to Alice Notice how new method is preceded by monitor not world o Means it is a class-level method not world-level o Will be saved if class is saved o If world is saved the class will not be saved for future use in other programs Can only use this in this new method in this specific program
20
Using turnOnOff Method Variable monitor.isOn is set initially to true In world.My first method o Turn off monitor using turnOnOFF Variable monitor.isOn is now set to false o Wait 1 second to see effect o Turn on monitor using turnOnOFF
21
Built-in Functions We have been using built-in functions so far
22
How a Function Works A function o Receives value(s) as arguments in parameters o Performs computations on the value(s) o Returns (sends back) a value
23
Types of Functions The function type depends on the type of value it returns Examples o Number o Specific object o Boolean (true or false) o Color o Other property values…
24
Create Function Click on create new function in class or world you want it to be in Name function and choose type of function A blank function will be created with return statement Return statement will be returned when function is done o Place value you want returned in return statement
25
Function Window Since no action is performed in a function all instructions will be performed in sequential order o No need for Do in order and Do together o All will be Do in order Notice that you can place return elsewhere in function
26
Calorie Example A high school jock wants to know how many calories a cookie has He asks a lunch lady She consults the newly created calorie function o 1 meter wide cookie = 1000 calories Number Function calories Parameter: food Local Number variable: numCalories If food = cookie numCalories = cookie’s width *1000 Return numCalories
27
Storyboard Translated to Alice My first method has jock as lunch lady for the calories in the cookie The lunch lady checks how many calories with the calorie function and answers with the amount of calories
28
Visual Effects and Animation Billboards Fog Vehicles asSceneBy Circling Other Objects Pose Programming the Camera Creating Dummy Objects
29
Billboards Graphical images that have been inserted into the world Can insert images that are JPEG, GIF, TIF Known as “Billboard” Images are flat, 2D with height and width no depth Can be used as backgrounds or scenery or used to give info to the viewer! Boy are you shallow, you’re only 2D!
30
Information Billboard Can be used as sign for instructions
31
Creating Billboard Can import images using Make Billboard In File menu
32
Fog Alice can give a look of “mist” to the world The entire world becomes less visible
33
Vehicle Property To have two objects move as one One object will be carried by another object o Ex: person on horse Horse is vehicle for person Choose properties tab o In property of object being carried In vehicle choose object doing carrying
34
asSceneBy Argument All objects are egocentric To move one object in relation to another choose asSceneBy in more option of a method Ex: To rotate fish around island o Without asSceneBy fish would go in straight line
35
Circling Other Objects Object’s turn method spins the object around The turn method can also have an object circle around another object The asSeenBy argument causes an object to turn around the asSeenBy’s objects center point Example: the hawk turns one complete revolution, asSeenBy the tree, around the tree
36
Pose Once an object has been put into a position or pose, the pose can be restored during an animation o Pose is a property of an object o setPose is a method of an object
37
Programming the Camera Camera can be programmed just like other objects All the same primitive methods and functions are available for it: o Point at, Move, Turn, etc. Camera can also be a vehicle for other objects!
38
Creating Dummy Objects Dummy objects are invisible objects that are placed in the world Camera then moves to the invisible object to get different perspectives
39
Homework Read chapter 6 sections 1,2,6,7 Answer questions in handout Do lab assignments after handing in answered questions Due one week after assigned with 1 week grace
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.