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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:46:12+00:00 2026-06-12T19:46:12+00:00

Need help, I am tring to make an android game as project for my

  • 0

Need help, I am tring to make an android game as project for my school.
I try to use ontouchListener in order to bump the mole.

Main Activity

public class First_Stage extends Activity implements OnTouchListener{

private AllViews allViews;
private MoleView moleView;
private PointsView pointsView;
private TimerView timerView;
private StageView stageView;
private Mole mole; 
private MoveMole moleMove;
private int points=0;
private StagePoints stagePoints;
private PointsSingelton poin;
private float x,y;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    mole=new Mole();
    stageView=new StageView(this);
    moleView=new MoleView(this,mole,x,y);
    pointsView=new PointsView(this);
    timerView=new TimerView(this, "3:33");

    allViews=new AllViews(this);
    allViews.setViews(stageView, moleView, pointsView, timerView);

    setContentView(allViews);
    allViews.setOnTouchListener((View.OnTouchListener)this);

}

@Override
public boolean onTouch(View v, MotionEvent event) {
    x=event.getX();
    y=event.getY();

    return true;
}

All views class

public class AllViews extends SurfaceView implements SurfaceHolder.Callback, Runnable{

private MoleView moleView;
private PointsView pointsView;
private TimerView timerView;
private StageView mainView;
private float x,y;
private Paint test;
private First_Stage first;
Thread drawThread = new Thread(this);
SurfaceHolder holder;


public AllViews(Context context) {
    super(context);
    test=new Paint();
    first=new First_Stage();
    holder= getHolder();
    holder.addCallback(this);
}


public void setViews(StageView mainView, MoleView moleView, PointsView pointsView,TimerView timerView)

{
    this.mainView = mainView;
    this.moleView = moleView;
    this.pointsView = pointsView;
    this.timerView = timerView;

}
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    mainView.onDraw(canvas);    
    moleView.onDraw(canvas);
    pointsView.onDraw(canvas);
    timerView.onDraw(canvas);
    test.setColor(Color.BLUE);
    canvas.drawCircle(first.getX(), first.getY(), 40, test);

}



@Override
public void run() {
     Canvas c;
        while (true) {
            c = null;

            try {
                c = holder.lockCanvas(null);

                synchronized (holder) {
                    onDraw(c);

                }
            } finally {

                if (c != null) {
                    holder.unlockCanvasAndPost(c);
                }

            }
        }                   
}


@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    // TODO Auto-generated method stub

}


@Override
public void surfaceCreated(SurfaceHolder holder) {
    drawThread.start();     

}

I have also class to mole, points,time and the stage screen. but I don’t know in which view to make the ontouchlistener.
for a try I made a blue circle and try to change it’s place with the new positions from the listener event but no lack.

any help will be great.
thanks,

cfir.

  • 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-12T19:46:13+00:00Added an answer on June 12, 2026 at 7:46 pm

    It looks to me like you need to let AllViews know that you received the information from the touch.

    You could create a couple of properties in AllViews

    private int touchX;
    private int touchY;
    
    public void setTouchX(int x) { this.touchX = x; }
    
    public void setTouchY(int y) { this.touchY = y; }
    

    and then in your onTouch method add these lines before the return statement:

    AllViews.setTouchX(x);
    AllViews.setTouchY(y);
    

    and finally, in your onDraw method, change

    canvas.drawCircle(first.getX(), first.getY(), 40, test);
    

    to

    canvas.drawCircle(this.touchX, this.touchY, 40, test);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help with Android. I'm trying to create a slot machine game. So,
I need some help on android.., apparently, I'm trying to make a progress dialog
Need your guidance, I am writing one app in android with the help of
I am trying to make SELECT statement for following situation and need help to
I need help with Facebook OAuth. I am trying to make a facebook news
I'm trying to make an android game here, but I'm not sure what is
I'm trying to make my first android game and to do this I made
I'm trying to make an Android application that need to access some webservices, returning
I need to port a fairly large Visual C/C++ Project to Android in my
So after several Advil's I think I need help I am trying to make

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.