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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:04:30+00:00 2026-06-13T00:04:30+00:00

I am making an Android game. The game is moles that appear on different

  • 0

I am making an Android game. The game is moles that appear on different places on the screen at random intervals for random durations.

The problem is I don’t know how to make the mole stay visible for a few seconds. I used wait(1000) on the the holder of OnDraw(), but it made the game stack for this time. I tried to change SurfaceView back to View, but then the screen stopped refreshing.

Any advice?

Main activity Class

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;
private Club club;
private ClubView clubView;
private PointsSingelton pointsCount;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    club=new Club();
    clubView = new ClubView(this, club);
    mole=new Mole();
    stageView=new StageView(this);
    moleView=new MoleView(this,mole);
    pointsView=new PointsView(this);
    timerView=new TimerView(this, "3:33");

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

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

}

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

    allViews.setX(x);
    allViews.setY(y);


    if ((x<100 && x>0)&&(y>0&&y<100)){  
    points=pointsCount.getInstance().nextPoint();
    pointsView.setPoint(points);
    moleView.setBool(true);
    }

    return true;
}

All Views Class

public class AllViews extends SurfaceView implements SurfaceHolder.Callback,Runnable {
private Club club;
private ClubView clubView;
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;
private Bitmap clubPic;


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,ClubView clubView)

{
    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);
    clubPic=BitmapFactory.decodeResource(getResources(), R.drawable.clubdown);
    canvas.drawBitmap(clubPic, this.x-39,this.y-20, null);

}

@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();

}

moleView Class

public class MoleView extends View {
private Mole  mole;
private Bitmap molePic;
private float x,y;
private boolean bool=false;

public MoleView(Context context, Mole mole) {
  super(context);
  this.mole=mole;

    }


public boolean isBamped(){
    float xmin=mole.getX();
    float xmax=mole.getX()+60;
    float ymin=mole.getY();
    float ymax=mole.getY()+46;
    if ((this.x<xmax&&this.x>xmin)&&(this.y<ymax&&this.y>ymin)){
        return true;
    }

    return false;
}



@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub

    if (!bool){
    molePic=BitmapFactory.decodeResource(getResources(), R.drawable.nest_full_mole);
    canvas.drawBitmap(molePic, mole.getX(), mole.getY(), null);
      mole.moveMole();
    }else {
        molePic=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        canvas.drawBitmap(molePic, mole.getX(), mole.getY(), null);
        molePic.recycle();
    }


}

Mole Class

public class Mole {
private float x;
private float y;
private Positions myPositions;

public Mole() {
    super();        
    myPositions=new Positions();
    this.x = myPositions.getRandomX();
    this.y = myPositions.getRandomY();
}


public float getX() {
    return x;
}
public void setX(float x) {
    this.x = x;
}
public float getY() {
    return y;
}
public void setY(float y) {
    this.y = y;
}
}
  • 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-13T00:04:31+00:00Added an answer on June 13, 2026 at 12:04 am

    I can’t really find the place in code where do you want to keep it on screen, because there is still a lot of code but try it like this:

    Make a new Handler in the class where you are drawing the moles. After that, you can call the postDelayed() function, with which you can execute something in the period you define. Quite simple, in fact.

    Links:
    http://developer.android.com/reference/android/os/Handler.html

    http://www.vogella.com/articles/AndroidPerformance/article.html

    • 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 delete some falling images from the
I am making an android game that should display a message that you have
I am making game for android using libgdx my requirement is that when character
I am making a card game in java/android. The idea is simple, a random
I am making an android 2d game and ran into a problem. I made
All right, so I'm making a game for Android. For the menu screen, I
I am making an android game that spawns enemy sprites at a certain interval
I'm making a game for the Android platform and I need to access some
I am also new to Java and Android Development, been making a simple game
I am making an android app for http://yearbook08.com/ I know how to parse through

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.