Wednesday, November 12, 2014

Coursera Graphics assignment

When the user touches this empty screen, one new bubble should appear on the display.  
The bubble should then begin to move around the screen. The Bubble’s size, direction and speed should be randomized within limits explained in source code skeleton.  
Assuming the Bubble’s direction is up and to he right, the Bubble shown above might be in the following location after a couple seconds.  
As the user continues to touch empty spaces on the screen, more bubbles should be added.
If the user presses the screen at a location already occupied by a bubble, then the bubble should “pop.”  
That is, it should be removed from the screen and a bubble popping sound should be played.  
The sound file is in the skeleton code in the /res/raw/ bubble_pop.wav file.   
In addition, if the user executes a "fling" gesture starting at a location already occupied on the screen, then the application should change the bubbles current direction and speed to match the direction and speed of the fling gesture.

make a new SoundPool, allowing up to 10 streams - see :

  • SoundPool mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

set a SoundPool OnLoadCompletedListener that calls a  method- see :
mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
if (0 == status) {

load the sound from res/raw/bubble_pop.wav -  see : 

mSoundID = mSoundPool.load(this, R.raw.bubble_pop, 1);

get all Views in mFrame one at a time

RelativeLayout mFrame;mFrame = (RelativeLayout) findViewById(;get all Views in mFrame one at a time// using the ViewGroup.getChildAt() methodmFrame.getChildCount();(BubbleView) mFrame.getChildAt(i); 

create the scaled bitmap using size set above - see :

final Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.b128);mScaledBitmap = Bitmap.createScaledBitmap(bitmap,mScaledBitmapWidth, mScaledBitmapWidth, false);

BubbleView extends View

  • setRotation(Random r) 
  • setSpeedAndDirection(Random r) 
  • createScaledBitmap(Random r)
  • startMovement() {
  • intersects(float x, float y)
  • stopMovement(final boolean wasPopped) {
  • synchronized void deflect(float velocityX, float velocityY) {
  • moveWhileOnScreen() 
  • isOutOfView()

No comments:

Post a Comment