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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:14:01+00:00 2026-06-05T06:14:01+00:00

What I need to do is have a loop that I can stop if

  • 0

What I need to do is have a loop that I can stop if I want… I made a new thread and named it GameLoop I want this to do all of my bitmap X and Y changes but when I tryed to run what I have nothing moves, It just sends me a picture. Heres my code, what did I do wrong?

 public GamePage(Context context, AttributeSet attrs) 
    {
        super(context, attrs);
            //other code here
            Thread gameThread = new Thread(new GameLoop());
            gameThread.start();  
    }

public class GameLoop implements Runnable
{
    public void run()
    {
        try {
            Thread.sleep(speed);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Log.d("LoopRunning", "The Game Loop Is Running!");

        switch ((int)possition)
        {
        case 0:
            if (counter < 110) {SunY --; counter++;}
            if (counter >= 110 && counter < 240) {SunY --; SunX ++; counter++;} 
            if (counter >= 240 && counter < 360) {SunY -= 0.5; SunX ++; counter++;}
            if (counter >= 360 && counter < 662) {SunY -= 0.333; SunX ++; counter++;}
            if (counter >= 662 && counter < 1004) {SunY += 0.333; SunX++; counter++;}
            if (counter >= 1004 && counter < 1104) {SunY += 0.5; SunX++; counter++;}
            if (counter >= 1104 && counter < 1224) {SunY ++; SunX++; counter++;}
            if (counter >= 1224 && counter < 1345) {SunY ++; counter++;}
            break;

        case 1:
            if (ZombieX < canvasWidth/2 + 300) ZombieX += 10;

            if (counter2 < 110) {MoonY --; counter2++;}
            if (counter2 >= 110 && counter2 < 240) {MoonY --; MoonX ++; counter2++;} 
            if (counter2 >= 240 && counter2 < 360) {MoonY -= 0.5; MoonX ++; counter2++;}
            if (counter2 >= 360 && counter2 < 662) {MoonY -= 0.333; MoonX ++; counter2++;}
            if (counter2 >= 662 && counter2 < 1004) {MoonY += 0.333; MoonX++; counter2++;}
            if (counter2 >= 1004 && counter2 < 1104) {MoonY += 0.5; MoonX++; counter2++;}
            if (counter2 >= 1104 && counter2 < 1224) {MoonY ++; MoonX++; counter2++;}
            if (counter2 >= 1224 && counter2 < 1345) {MoonY ++; counter2++;}
            break;
        }
    }
}
  • 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-05T06:14:03+00:00Added an answer on June 5, 2026 at 6:14 am

    Use two nested while loops as so:

    @Override public void run() {
        while (gameShouldRun) {
            while (iterateGame) {
                // do game stuff
            }
        }
    }
    

    Also, run is not looped by default. If you want the game to loop until stopped, you will need a while loop in the run method.

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

Sidebar

Related Questions

I have a thread containing a runnable. I need this to loop infinitely unless
I have code that needs to loop and it will need to change the
I have a number rather large, complex xml documents that I need to loop
I have a PHP script with infinite loop. I need this script running forever.
Hi I'm new to JQuery. I have an two issues that I can't figure
I need a way to stop a worker thread that does not contain a
I have a foreach loop that I need to pause in order to allow
I have made a loop in my JavaScript code and in that loop I
I have a foreach loop in jQuery going through each 'div.panel', I need to
i have the following code ..i need to loop through end of the file

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.