Download presentation
Presentation is loading. Please wait.
Published byLambert Lyons Modified over 6 years ago
5
Technologies Overview
Media files, such as the sounds, are placed in the app’s resource folder res/raw. When an Activity is shut down, its Fragment lifecycle onDestroy method is called, which in turn calls the onDestroy methods of all the Fragments hosted by the Activity. A touch aligns the cannon to face the touch point on the screen, then fires the cannon. Override View method onTouchEvent. An app’s sound effects are managed with a SoundPool (package android.media), which can be used to load, play and unload sounds.
6
Technologies Overview
This app performs its animations manually by updating the game elements from a separate thread of execution. Use a subclass of Thread with a run method that directs our custom CannonView to update the positions of the game’s elements, then draws them. The run method drives the frame-by-frame animations—this is known as the game loop. Android provides class SurfaceView—a subclass of View that provides a dedicated drawing area in which other threads can display graphics on the screen in a thread-safe manner.
7
Technologies Overview
The CannonView performs simple collision detection to determine whether the cannonball has collided with any of the CannonView’s edges, with the blocker or with a section of the target.
8
Overview of This App’s Classes
MainActivity hosts the MainActivity Fragment. MainActivityFragment displays the CannonView. GameElement, the superclass for items that move up and down or across (Cannonball) the screen. Blocker makes destroying targets more challenging. Target represents a target that can be destroyed by a cannonball. Cannon represents the cannon, which fires a cannonball each time the user touches the screen. Cannonball represents a cannonball that the cannon fires when the user touches the screen. CannonView contains the game’s logic and coordinates the behaviors of the Blocker, Targets, Cannonball and Cannon.
9
Let’s look at the codes:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.