android - Using a thread as a GameLoop -


what need have loop can stop if want... made new thread , named gameloop want of bitmap x , y changes when tryed run have nothing moves, sends me picture. heres code, did 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 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;         }     } } 

use 2 nested while loops so:

@override public void run() {     while (gameshouldrun) {         while (iterategame) {             // game stuff         }     } } 

also, run not looped default. if want game loop until stopped, need while loop in run method.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -