Upload
natala
View
19
Download
0
Embed Size (px)
DESCRIPTION
CSS290 : Apps on Mobile Devices. Lecture 6: Thread Safe Event services and Coordinate System. Today: Concepts. Reading: Chapter 5 Sensors and Services Thread invoking functions Delegates Logica l Coordinate Control by Orientation vs. Hardware Coordinate from Accelerometer. - PowerPoint PPT Presentation
Citation preview
Lecture 6: Thread Safe Event services and Coordinate System
CSS290: APPS ON MOBILE DEVICES
TODAY: CONCEPTS• Reading: Chapter 5
• Sensors and Services
• Thread invoking functions
• Delegates
• Logical Coordinate Control by Orientation vs. Hardware Coordinate from Accelerometer
DELEGATE KEYWORD: A FUNCTION POINTER• Define a data type that accepts a function!
• delegate returnType TypeName(parameter list)
• E.g. delegate void MyFuncType(double a, double b)
• New datatype is: MyFuncType!
• Convenient for passing function pointers around!
ADDING A NEW REFERENCE INTO IDE• The Reference Tab in the Solution Explorer
• Finding the right reference
• Using the reference in your code
• To work with Accelerometer we need
• Microsoft.Devices.Sensors
1. ACCTEST: ACCELEROMETER• Event service is called form an external thread
• SHOULD NOT change our variable from that service routine
• Called from external thread, danger of external thread and our own thread trying to change the same variable!
• Instead: BeginInvoke() called sometime later when it is safe.
• Accelerometer X/Y/Z
• Resting state for Z is -1 (gravitational pull)
• Notice: -Y is downwards.
• X/Y is associated with the hardware
• If you change the phone orientation, X/Y direciton DOES NOT change
2. ACC CONTROLS OBJ:• Accelerometer with Orientation
• Phone orientation changes the logical X/Y directions
• Accelerometer returns the same X/Y/Z readings regardless of phone orientation!
• We must translate the change!
• Switch on Orientation changing support
• Translate coordinate space depending on phone orientation
3. BOUND CHECK• Switch off orientation (annoying)
• mBall class
• Passed in ContentPanel for bound checking
• Random position inside the bound
• Bound intersection checking
• Test for X overlaps
• Test for Y overlaps
• Must satisfy all conditions for potential collision
EXERCISE 6:• Integrate Bound checking with Exercise 5
• Check for ball touch net in Timer service (nice central place)
• Integrate Music/Sound effect
• Integrate Accelerometer for moving the net
• No need for orientation support
• BECAREFUL!!
• mTheNet must be a Shape! (Rectangle)!!
• UIImage does _NOT_ work!!