我需要做的是有一个循环,如果我愿意,我可以停止......我创建了一个新线程并将其命名为 GameLoop 我希望它完成我所有的位图 X 和 Y 更改,但是当我尝试运行我所拥有的什么都没有动,它只是给我发了一张照片。这是我的代码,我做错了什么?
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;
}
}
}