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

  • Home
  • SEARCH
  • 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 6903883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:58:51+00:00 2026-05-27T07:58:51+00:00

I am developing an android game. in this i have two moving images on

  • 0

I am developing an android game. in this i have two moving images on the screen, am able to drag this images, but my further requirement is to pause the image when i touch the image. am not finding any event to pause the image , and than restart moving at the same position where image have been paused.

Can any body tell me the solution.
Thanks.

am using onTouch to drag and move the image.

public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            Parcelable state=null;
            // delegating event handling to the droid
            droid1.handleActionDown((int)event.getX(), (int)event.getY());
            droid2.handleActionDown((int)event.getX(), (int)event.getY());
            // check if in the lower part of the screen we exit
            if (event.getY() > getHeight() - 50) {

                thread.setRunning(false);
                ((Activity)getContext()).finish();
            } else {
                Log.d(TAG, "Coords: x=" + event.getX() + ",y=" + event.getY());

            }
        } if (event.getAction() == MotionEvent.ACTION_MOVE) {
            // the gestures
            if (droid1.isTouched()) {
                // the droid was picked up and is being dragged
                droid1.setX((int)event.getX());
                droid1.setY((int)event.getY());

            }
            if (droid2.isTouched()) {
                // the droid was picked up and is being dragged
                droid2.setX((int)event.getX());
                droid2.setY((int)event.getY());
            }

        } if (event.getAction() == MotionEvent.ACTION_UP ) {
            // touch was released
            if (droid1.isTouched()) {
                droid1.setTouched(false);
            }
            if (droid2.isTouched()) {
                droid2.setTouched(false);
            }
        }


        return true;
    }
  • 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-27T07:58:51+00:00Added an answer on May 27, 2026 at 7:58 am

    Based on your code and de link in your comment, there are a few things that need to be changed in order to accomplish your goal. First of all, you will need to be able to differentiate between a single tap and drag movement. The former will ‘pause’ an image/droid, whereas the latter will allow you to drag it around.

    One way to go at this would be to keep a flag that determines the action. Something like this:

    private boolean mIsDragging = false;
    
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            // delegating event handling to the droid
            droid1.handleActionDown((int)event.getX(), (int)event.getY());
            droid2.handleActionDown((int)event.getX(), (int)event.getY());
            ...
            mIsDragging = false;
        } if (event.getAction() == MotionEvent.ACTION_MOVE) {
            // the gestures
            if (droid1.isTouched()) {
                // the droid was picked up and is being dragged
                droid1.setX((int)event.getX());
                droid1.setY((int)event.getY());
            }
            if (droid2.isTouched()) {
                // the droid was picked up and is being dragged
                droid2.setX((int)event.getX());
                droid2.setY((int)event.getY());
            }
            mIsDragging = true;  
        } if (event.getAction() == MotionEvent.ACTION_UP ) {
            if (!mIsDragging) {
                // Not dragging means a 'click', thus toggle pausing
                if (droid1.isTouched()) {
                    droid1.setPaused(!droid1.isPaused());
                }
                if (droid2.isTouched()) {
                    droid2.setPaused(!droid2.isPaused());
                }
            }
            // Always reset on up action
            if (droid1.isTouched()) {
                droid1.setTouched(false);
            }
            if (droid2.isTouched()) {
                droid2.setTouched(false);
            }
            mIsDragging = false;
        }
        return true;
    }
    

    To actually stop the image/droid from making anymore movements, you should add some method to set the speed in both horizontal and vertical direction to ‘0’. Alternatively, you could set a flag that indicates whether you want to update the position.

    Based on which approach you take, you may also have to change the update logic to take into account the ‘paused’ state. If you simply choose to set the speed to (0,0), then you’ll probably won’t have to do anything as the displacement will then result in ‘0’ for both directions.

    In the code snippet I’m assuming there’s a setPause(boolean) and isPaused() method. These should either work on a flag or the speed values directly.

    For example, using a flag:

    private boolean mIsPaused = false;
    
    public void setPaused(boolean pause) {
        mIsPaused = pause;
    }
    
    public boolean getPaused() {
        return mIsPaused;
    }
    
    ...
    
    public void update() {
        // Only update if we're not dragging and not 'paused'
        if (!touched && !mIsPaused) {
            x += (speed.getXv() * speed.getxDirection());
            y += (speed.getYv() * speed.getyDirection());
        }
    }
    

    Or directly using the speed values:

    private Speed mSpeed = new Speed(1,1);
    
    public void setPaused(boolean pause) {
        pause ? mSpeed.setSpeed(0,0) : mSpeed.setSpeed(1,1);
    }
    
    public boolean getPaused() {
        return mSpeed.getX() == 0 && mSpeed.getY() == 0;
    }
    
    ...
    
    public void update() {
        // No change necessary as multiplying by '0' results in a zero displacement
    }
    

    Note that I have not tested any of the code nor is it intented to be a complete example.

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

Sidebar

Related Questions

I'm developing an android app, and have developed a game, but I now have
I am developing an Android Game. In this game some trains are moving on
I am developing a game for Android. This game is Pacman, I have seen
I am developing an android game, in which i have some trains moving on
I'm currently developing a simple 2D game for Android. I have a stationary object
I'm currently developing an Android game which saves data into a SQLite database. This
I'm developing a crime themed android game that will have a high maturity rating
I am a new game developer and have started developing game for android. I
I'm developing a cross platform game engine this targets Windows, Linux, Mac, Mobiles(Android, iOS)
I have been developing Android apps, but never did a live wallpaper. I have

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.