January 2014
Intermediate to advanced
736 pages
70h 43m
English
In this example, we override View method onTouchEvent (Fig. 6.19) to determine when the user touches the screen. The MotionEvent parameter contains information about the event that occurred. Line 523 uses the MotionEvent’s getAction method to determine which type of touch event occurred. Then, lines 526–527 determine whether the user touched the screen (MotionEvent.ACTION_DOWN) or dragged a finger across the screen (MotionEvent.ACTION_MOVE). In either case, line 529 calls the cannonView’s fireCannonball method to aim and fire the cannon toward that touch point. Line 532 then returns true to indicate that the touch event was handled.
518 // called when the user touches ...
Read now
Unlock full access