我創建了一個 if 語句,如果是 true 就繼續運行。我想停止 "continue" ,然後創建另一個語句。例如 touchdown 和 touchup. 如何實現?
private void updateRunning(float deltaTime) {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int len = touchEvents.size();
for (int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type != TouchEvent.TOUCH_UP)
continue;
world.doodle.DOODLE_Y = 3;
touchPoint.set(event.x, event.y);
guiCam.touchToWorld(touchPoint);
if (OverlapTester.pointInRectangle(pauseBounds, touchPoint)) {
Assets.clicks();
state = GAME_PAUSED;
return;
}
}
world.update(deltaTime, game.getInput().getAccelX());
if (world.score != lastScore) {
lastScore = world.score;
scoreString = "" + lastScore;
}
if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
state = GAME_LEVEL_END;
}
if (world.state == World.WORLD_STATE_GAME_OVER) {
state = GAME_OVER;
if (lastScore >= Settings.highscores[4])
scoreString = "new highscore: " + lastScore;
else
scoreString = "score: " + lastScore;
Settings.addScore(lastScore);
Settings.save(game.getFileIO());
}
}
就將那兩句注釋掉,在此創建好了就break就跳出循環了
不過要注意,看樣子,一兩次循環你不一定能得到你想要的條件
要不然不會for都查一遍了
也可以這樣細分效率能高一些
switch(event.type){
case TouchEvent.TOUCH_DOWN:
//
break;
case TouchEvent.TOUCH_UP:
//
break;
default:
continue;
break;
}