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 4040306
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:44:10+00:00 2026-05-20T12:44:10+00:00

I have just started developing in Android and I am trying to make a

  • 0

I have just started developing in Android and I am trying to make a very basic game where you have to move a bat along the bottom of the screen and catch items while avoiding bombs.

The problem I am having is I want the bat to move along the bottom of the screen when you hold your finger on the left or the right side of the screen.

Currently I can get the bat to move a few pixels across when the user touches the screen but I can not get it to keep moving until the user removes his finger from the screen.

Here is my (very) basic code so far :

package com.mattdrewery.supercatch;

import android.view.View;
import android.view.MotionEvent;
import android.content.Context;
import android.graphics.Canvas;

public class GameView extends View 
{
    private Catcher catcher;

    public GameView(Context context)
    {
        super(context);
        setFocusable(true);

        // Create the catcher
        catcher = new Catcher(context, R.drawable.catcher, 240, 250);
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        // Draw the catcher to the canvas
        canvas.drawBitmap(catcher.getImage(), catcher.getPosX(),  catcher.getPosY(), null);

        // Redraw the screen
        invalidate();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        // Get the action from the touch screen
        int eventAction = event.getAction();

        int X = (int) event.getX();
        int Y = (int) event.getY();

        // If the user presses on the screen....
        if (eventAction == MotionEvent.ACTION_DOWN)
        {
            catcher.moveLeft();
        }

        // Redraw the screen
        invalidate();

        return true;
    }
}

The catcher.moveLeft() method is as follows:

public void moveLeft()
    {
        posX -= 5;
    }

Any help with this matter would be greatly appreciated! 🙂

  • 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-05-20T12:44:11+00:00Added an answer on May 20, 2026 at 12:44 pm

    I think this might just work:

    boolean actionUpFlag = false;
    
    
    if (eventAction == MotionEvent.ACTION_DOWN)
            {
                actionUpFlag = true;
            }
    else if (eventAction == MotionEvent.ACTION_UP)
            {
                 actionUpFlag = false;
            }
    
    while (actionUpFlag)
    {
         catcher.moveLeft();
    }
    

    Is this what you are looking for ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started developing iPhone applications and I am very confused by how
I have just started developing using Youtube API and stuck in very beginning. I
I have just started using Boost 1.36. These libraries would be very useful in
I have just started learning Erlang and am trying out some Project Euler problems
I'm just getting started developing for Android and I'm running into a weird problem.
At work we have just started developing in C#.NET using VS2008 and we need
I have just started with wordpress and want to start developing my own themes.
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have just started playing with ASP.NET MVC and have stumbled over the following situation.

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.