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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:06:34+00:00 2026-06-15T15:06:34+00:00

ok to i created an ontouchlistener class: package drop.out.Game; import android.view.MotionEvent; import android.view.View; import

  • 0

ok to i created an ontouchlistener class:

package drop.out.Game;

import android.view.MotionEvent;

import android.view.View;

import drop.out.Game.Model.Player;

public final class TrackingTouchListener 

 implements View.OnTouchListener{

//player class
private final Player mplayer;
Player plyr;

//constructor bringing in the player
TrackingTouchListener(Player plyr){mplayer = plyr;}

    //on touch stuff
     public boolean onTouch(View v, MotionEvent evt) {

         /**@if touching/moving on the left side of screen */
         if(MotionEvent.ACTION_DOWN== evt.getAction() && evt.getX() < (v.getWidth()/2) || MotionEvent.ACTION_MOVE== evt.getAction() && evt.getX() <(v.getWidth()/2)){
             moveL(mplayer);
         }
         /**@if touching/moving on the right side of the screen */
         if(MotionEvent.ACTION_DOWN== evt.getAction() && evt.getX() > (v.getWidth()/2) || MotionEvent.ACTION_MOVE== evt.getAction() && evt.getX() >(v.getWidth()/2)){
             moveR(mplayer);
         } 

         return true; 
     }

     //call functions in the player class that moves the player x by -1
     private void moveL(Player player){
         player.moveL();
         //e.g. player_x -=10;
     }

     private void moveR(Player player){
         player.moveR();  
         //e.g.player_x +=10;
     }

}

Unfortunately the player_x is only updated when the screen is pressed or dragged across, I was hoping to have it move when the finger is on ether side of the screen.
Any ideas?

  • 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-15T15:06:36+00:00Added an answer on June 15, 2026 at 3:06 pm

    If you’re not moving your finger, you’ll stop getting updates.

    Instead of calling move from the TouchListener, you should set a boolean flag like shouldMove, and then at a fixed interval issue a move command if shouldMove is true.

    Then your character will continue to move even when you stop receiving touch events. Just clear this boolean when you lift your finger, or move out of a certain area.

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

Sidebar

Related Questions

i have this code package com.tct.soundTouch; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.MotionEvent;
I created a following class within a namespace Global namespace Global { public static
Android SDK has an interface in TouchEvent . ( android.view.View.OnTouchListener ) I don't know
I have created a class (InputControl) which extends the view of my main class
I created a PHP Drop Down which is populated from a MySql Database and
I've created a custom view by extending View, it draws fine but When i
Im trying to learn Android graphics & event handeling for a multiplayer game. As
I created a game with timer, I am trying to make that when the
i have created a coverflow using the code given by http://android.jmsliu.com/138/android-infinite-loop-gallery.html . And it
Hi I created a media player. It displays the number of video thumbnails. If

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.