Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 6: Thread Safe Event services and Coordinate System CSS290: APPS ON MOBILE DEVICES.

Similar presentations


Presentation on theme: "Lecture 6: Thread Safe Event services and Coordinate System CSS290: APPS ON MOBILE DEVICES."— Presentation transcript:

1 Lecture 6: Thread Safe Event services and Coordinate System CSS290: APPS ON MOBILE DEVICES

2 TODAY: CONCEPTS Reading: Chapter 5 Sensors and Services Thread invoking functions Delegates Logical Coordinate Control by Orientation vs. Hardware Coordinate from Accelerometer

3 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!

4 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

5 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

6 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

7 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

8 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!!


Download ppt "Lecture 6: Thread Safe Event services and Coordinate System CSS290: APPS ON MOBILE DEVICES."

Similar presentations


Ads by Google