Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cannon Game 1 Fall 2014 CS7020: Game Design and Development.

Similar presentations


Presentation on theme: "Cannon Game 1 Fall 2014 CS7020: Game Design and Development."— Presentation transcript:

1 Cannon Game 1 Fall 2014 CS7020: Game Design and Development

2 SurfaceView & SurfaceHolder  SurfaceView: – A subclass of view ti which any thread can draw  SurfaceHolder: – SurfaceHolder can manipulate a SurfaceView – SurfaceHolder can obtain a Canvas on which the user can draw graphics – SurfaceHolder provides methods that give a thread exclusive access to the Canvas for drawing  Each SurfaceView should implement the interface SurfaceHolder.Callback 2 Fall 2014 CS7020: Game Design and Development

3 SurfaceHolder.Callback Methods  SurfaceChanged: – is called when the SurfaceView’s size or orientation changes, and is typically used to redisplay graphics based on changes  SurfaceCreated: – is called when the SurfaceView is created, e.g. when the app first loads or when it resumes from the background  SurfaceDestroyed – is called when the SurfaceView is destroyed, e.g., when the app terminates 2 Fall 2014 CS7020: Game Design and Development

4 Use Thread to create game loop  Obtain the canvas – SurfaceHolder.lockCanvas(null);  Only one thread at a time can draw to a SurfaceView, we must lock the SurfaceHolder – Synchronized(SurfaceHolder){……}  Release the canvas – SurfaceHolder.unlockCanvasAndPost(canvas ); 2 Fall 2014 CS7020: Game Design and Development

5 AlertDialog.Builder  A dialog must be displayed from the GUI main thread  Anonymous inner class implements Runnable  activity.runOnUiThread( new Runnable(){ public void run(){ } ) 5 Fall 2014 CS7020: Game Design and Development

6 GestureDetector  Complex gesture, such as flings, double-taps, long presses, and scrolls  Implement GestureDetector.OnGestureListener and GestureDetector.OnDoubleTapListener interfaces  GestureDetector.SimpleOnGestureListener is an adapter class that implements all the methods of these two interfaces 6 Fall 2014 CS7020: Game Design and Development

7 Collision Detection  Determine whether the cannonball has collided with any of the GameView’s edges, with the blocker or with a section of the target  We perform simple collision detection based on the rectangular boundary of the cannonball 7 Fall 2014 CS7020: Game Design and Development

8 Activity Lifecycle Methods  onPause is called when another activity receives the focus – suspend game play so that the game does not continue executing when the user cannot interact with it  onDestroy is called when an Activity is shut down. – Release the app’s resources 7 Fall 2014 CS7020: Game Design and Development

9 Audio Mangement  res/raw --- media files  Sound effects are managed with a SoundPool, which can be used to load, play, and unload sounds  The android documentation recommends that games use the music audio stream to play sounds  Activity’s setVolumeControlStream specify that the game’s volume can be controlled with the device’s volume keys. The method receives a constant from class AudioManager 10 Fall 2014 CS7020: Game Design and Development

10 SoundPool  First argument: the maximum number of simultaneous sound streams that can play at once  Second argument: which audio stream will be used to play the sounds – There are 7 streams in AudioManager – The document recommends AudioManager.STREAM_MUSIC  Last argument: sound quality. – The document indicates that this value is not currently used and 0 should be specified as the default value 10 Fall 2014 CS7020: Game Design and Development

11 SoundMap  HashMap --- key, value pairs – soundMap = new HashMap ();  SoundPool.load take three parameters – First argument: the application’s context – Second argument: resource ID – Third argument: the sound’s priority (the argument is not currently used and should be specified as 1). 10 Fall 2014 CS7020: Game Design and Development


Download ppt "Cannon Game 1 Fall 2014 CS7020: Game Design and Development."

Similar presentations


Ads by Google