80 likes | 161 Views
Explore the use of delegates, logical coordinates, and accelerometer functionality for creating robust threads and coordinate systems in mobile app development. Learn to integrate bound checking and accelerometer features effectively.
E N D
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 • Logical Coordinate Control by Orientation vs. Hardware Coordinate from Accelerometer
Delegate keyword: a function pointer • Define a data type that accepts a function! • delegate returnTypeTypeName(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!!