Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7706509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:08:33+00:00 2026-06-01T00:08:33+00:00

I am making an android game that should delete some falling images from the

  • 0

I am making an android game that should delete some falling images from the screen once they are tapped.
I thought that I maybe could use some similar code as seen on the doDraw() method, that deletes them once they hit the bottom of the screen, that also plays a sound, and checks the players health value. But I need a little bit of help with this. If anyone could post me any code and explain to me how this is done I would be very grateful!

This is the code that I am using so far:

public class ExampleView extends SurfaceView implements SurfaceHolder.Callback
{
class ExampleThread extends Thread
{
    private ArrayList<Parachuter> parachuters;
    private Bitmap parachuter;
    private Paint black;

    private boolean running;

    private SurfaceHolder mSurfaceHolder;
    private Context mContext;
    private Context mContext1;
    private Handler mHandler;
    private Handler mHandler1;
    private GameScreenActivity mActivity;

    private long frameRate;
    private boolean loading;
    public float x;
    public float y;
    public MediaPlayer mp1;
    public int parachuterIndexToResetAndDelete;
    public int canvasGetWidth;
    public int livesLeftValue;

    public ExampleThread(SurfaceHolder sHolder, Context context, Handler handler)
    {
        mSurfaceHolder = sHolder;
        mHandler = handler;
        mHandler1 = handler;
        mContext = context;
        mActivity = (GameScreenActivity) context;

        parachuters = new ArrayList<Parachuter>();
        parachuter = BitmapFactory.decodeResource(getResources(), R.drawable.parachuteman);
        black = new Paint();
        black.setStyle(Paint.Style.FILL);
        black.setColor(Color.WHITE);

        running = true;

        // This equates to 26 frames per second.
        frameRate = (long) (1000 / 26);
        loading = true;
    }

    @Override
    public void run()
    {
        while (running)
        {
            Canvas c = null;
            try
            {
                c = mSurfaceHolder.lockCanvas();

                synchronized (mSurfaceHolder)
                {
                    long start = System.currentTimeMillis();
                    doDraw(c);
                    long diff = System.currentTimeMillis() - start;

                    if (diff < frameRate)
                        Thread.sleep(frameRate - diff);
                }
            } catch (InterruptedException e)
            {
            }
            finally
            {
                if (c != null)
                {
                    mSurfaceHolder.unlockCanvasAndPost(c);
                }
            }
        }
    }

    protected void doDraw(Canvas canvas)
    {
        canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), black);
        canvasGetWidth = canvas.getWidth();

        //Draw
        for (int i = 0; i < parachuters.size(); i++)
        {
            canvas.drawBitmap(parachuter, parachuters.get(i).getX(), parachuters.get(i).getY(), null);
            parachuters.get(i).tick();
        }

        //Remove
        for (int i = 0; i < parachuters.size(); i++)
        {
        if (parachuters.get(i).getY() > canvas.getHeight()) {
            parachuters.remove(i);
            onPlaySound();
            checkLivesLeftValue();
        }
    }
    }


    private void checkLivesLeftValue() {
        Log.d("checkLivesLeftValue", "lives = " + livesLeftValue);
        // TODO Auto-generated method stub
        if (livesLeftValue == 3) {
            //Message to display: "You lost!
            Log.d("checkLivesLeftValue", "calling onMethod now");
            onMethod();
        }
        else {
            livesLeftValue = livesLeftValue + 1;
            Log.d("checkLivesLeftValue", "increased lives to " + livesLeftValue);
        }
    }
    public void onMethod() {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getContext(), "You lost!", 15).show();
                livesLeftValue = 0;
                //Tell the user that he lost:
                android.content.Context ctx = mContext;
                Intent i = new Intent(ctx, playerLostMessageActivity.class);  
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                ctx.startActivity(i);
            }
        });
    } 

    public void onPlaySound()
    {
        try {
        mp1 = MediaPlayer.create(getContext(), R.raw.bombsound);
        mp1.start();
        } catch (Exception e) {
            e.printStackTrace();
            mp1.release();
        }
    }

    public boolean onTouchEvent(MotionEvent event)
    {
        if (event.getAction() != MotionEvent.ACTION_DOWN)
            return false;
        float x1 = event.getX();
        float y1 = event.getY();

        initiateDrawParachuters();

        return true;
    }

    public void initiateDrawParachuters()
    {
        drawParachuter1();
    }

    private void drawParachuter1() {
        // TODO Auto-generated method stub
        //Parachuter nr. 1
        x = 10;
        y = 40;

        Parachuter p = new Parachuter(x, y);
        parachuters.add(p);
        drawParachuter2();
    }

    private void drawParachuter2() {
        // TODO Auto-generated method stub
        //Parachuter nr. 2
        x = 50;
        y = 80;

        Parachuter p = new Parachuter(x, y);
        parachuters.add(p);
        drawParachuter3();
    }

    private void drawParachuter3() {
        // TODO Auto-generated method stub
        //Parachuter nr. 3
        x = 90;
        y = 120;

        Parachuter p = new Parachuter(x, y);
        parachuters.add(p);
        drawParachuter4();
    }

    private void drawParachuter4() {
        // TODO Auto-generated method stub
        //Parachuter nr. 4
        x = 140;
        y = 150;

        Parachuter p = new Parachuter(x, y);
        parachuters.add(p);
        drawParachuter5();
    }

    private void drawParachuter5() {
        // TODO Auto-generated method stub
        //Parachuter nr. 5
        x = 190;
        y = 170;

        Parachuter p = new Parachuter(x, y);
        parachuters.add(p);
        drawParachuter6();
    }

    private void drawParachuter6() {
        // TODO Auto-generated method stub
        //Parachuter nr. 6
        x = 240;
        y = 180;

        Parachuter p = new Parachuter(x, y);
        parachuters.add(p);
        drawParachuter7();
    }

    private void drawParachuter7() {
        // TODO Auto-generated method stub
        //Parachuter nr. 6
        x = 290;
        y = 180;

        Parachuter p = new Parachuter(x, y);
        parachuters.add(p);
    }

    public void drawParachuters()
    {
            Parachuter p = new Parachuter(x, y);
            parachuters.add(p);
            Toast.makeText(getContext(), "x=" + x + " y=" + y, 15).show();
    }

    public void setRunning(boolean bRun)
    {
        running = bRun;
    }

    public boolean getRunning()
    {
        return running;
    }
}

/** Handle to the application context, used to e.g. fetch Drawables. */
private Context mContext;

/** Pointer to the text view to display "Paused.." etc. */
private TextView mStatusText;

/** The thread that actually draws the animation */
private ExampleThread eThread;

public ExampleView(Context context)
{
    super(context);

    // register our interest in hearing about changes to our surface
    SurfaceHolder holder = getHolder();
    holder.addCallback(this);

    // create thread only; it's started in surfaceCreated()
    eThread = new ExampleThread(holder, context, new Handler()
    {
        @Override
        public void handleMessage(Message m)
        {
           // mStatusText.setVisibility(m.getData().getInt("viz"));
           // mStatusText.setText(m.getData().getString("text"));
        }
    });

    setFocusable(true);
}

@Override
public boolean onTouchEvent(MotionEvent event)
{
    return eThread.onTouchEvent(event);
}

public ExampleThread getThread()
{
    return eThread;
}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3)
{
    // TODO Auto-generated method stub
}

public void surfaceCreated(SurfaceHolder holder)
{
    if (eThread.getState() == Thread.State.TERMINATED)
    {
        eThread = new ExampleThread(getHolder(), getContext(), getHandler());
        eThread.start();
    }
    else
    {
        eThread.start();
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
    boolean retry = true;
    eThread.setRunning(false);

    while (retry)
    {
        try
        {
            eThread.join();
            retry = false;
        }
        catch (InterruptedException e)
        {
        }
    }
}
}

Parachuter class touched boolean:

    public boolean isTouched() {
    return touched;
}

public void setTouched(boolean touched) {
    this.touched = touched;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:08:34+00:00Added an answer on June 1, 2026 at 12:08 am

    When a parachuter is touched you just need to set a boolean in the Parachuter class signifying that it is now dead and should be removed. You can then change your onDraw remove section to look like this.

       for (int i = 0; i < parachuters.size(); i++)
        {
        if (parachuters.get(i).getY() > canvas.getHeight()) {
            parachuters.remove(i);
            onPlaySound();
            checkLivesLeftValue();
        } else if(parachuters.get(i).isDead) {
            parachuters.remove(i);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an android game that should display a message that you have
I'm making a Android app that basically plays video from a website on the
I'm developing an Android game that has to download some assets to the SD
I'm making a simple 2d game for the android platform, which works perfectly from
I am making game for android using libgdx my requirement is that when character
I built a TicTacToe game for android. And i want that there should be
I'm making a mobile game that has some complex game logic. I'd like to
I am also new to Java and Android Development, been making a simple game
So I'm making an android app that has more than 100 buttons,but you know
I am making an android application, which takes an image from camera and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.