Processing 试图在循环结束时使对象数组消失

Processing 试图在循环结束时使对象数组消失,processing,Processing,我做了一个游戏,你用鼠标做一个火箭移动,试图避免撞到从屏幕上掉下来的小行星。我一切正常,但当小行星和火箭相交后循环结束时,小行星仍会留在屏幕上。我试图在环圈发生时清除小行星,但我不确定如何清除 如果您想查看正在进行的操作,但它仅在处理过程中起作用,请访问我的游戏的链接: 这就是我到目前为止所做的: void draw(){ 背景(0,0230); m=毫秒(); //当游戏重新启动时,游戏将在0秒而不是从 上一场比赛 gameTime=millis()-startTime; //以秒为单位显示时

我做了一个游戏,你用鼠标做一个火箭移动,试图避免撞到从屏幕上掉下来的小行星。我一切正常,但当小行星和火箭相交后循环结束时,小行星仍会留在屏幕上。我试图在环圈发生时清除小行星,但我不确定如何清除

如果您想查看正在进行的操作,但它仅在处理过程中起作用,请访问我的游戏的链接:

这就是我到目前为止所做的:

void draw(){
背景(0,0230);
m=毫秒();
//当游戏重新启动时,游戏将在0秒而不是从
上一场比赛
gameTime=millis()-startTime;
//以秒为单位显示时间
文本大小(60);
填充(232、98、82);
文本(游戏时间/1000、790、60);
//显示有关如何玩游戏的说明
填充(232、98、82);
文本大小(60);
文本大小(15);
文本(“*在播放时按下一个键以获得些许惊喜”,15、20);
文本(“*移动鼠标以避开小行星”,15、38);
rocket1.display();
rocket1.face();
//在小行星对象中循环并移动它们。
//即使数组为[100],也只能循环通过您希望看到的数组(numAsteroid)
对于(int i=0;i我知道
noLoop()
非常性感,但是在你的情况下,我建议避免使用它。有几个原因,但主要原因是你不能调用
mousePressed()
keyPressed()
,在你的游戏屏幕上,这似乎是你想要做的事情

相反,您可以使用
gameOver
boolean将绘制循环拆分为绘制游戏或在屏幕上绘制游戏,并获得类似的结果。这里我匆忙抛出了一个它可能看起来像什么的示例:

void draw() {
  if (gameOver) {
    DrawGameOverScreen();
  } else {
    DrawGame();
  }
}

void DrawGame() {
  background(0, 0, 230);
  m = millis();

  //when game restarts the game will restart at 0 seconds rather than the time from the 
  //previous game played 
  gameTime = millis()- startTime;


  //displays time is in seconds
  textSize(60);
  fill(232, 98, 82);
  text(gameTime / 1000, 790, 60); 


  // displays instructions about how to play the game
  fill(232, 98, 82);
  textSize(60);
  textSize(15);
  text("*Press a key for a little suprise while playing", 15, 20);
  text("*Move mouse to avoid the asteroids", 15, 38);

  rocket1.display();
  rocket1.face();

  //loop through Asteroid objects and move them.
  //even though array is [100], only loop through the ones you want to see (numAsteroid)
  for (int i=0; i<numAsteroid; i++) {
    myAsteroidArray[i].display();  
    myAsteroidArray[i].move();    
    myAsteroidArray[i].topPop();  


    if (rocket1.intersect(myAsteroidArray[i])) {
      //when the rocket hits an asteroid loop will stop and display the text and a circle

      //noLoop();

      gameOver = true;
    }
  }
}

void DrawGameOverScreen() {
  ////xPosition, yPosition, xSpeed, color
  background(57, 169, 219); 
  //display text for instructions about the game
  fill(232, 98, 82);
  textSize(60);
  text(0, 255, 0);
  text("Click Circle to Play", 191, 370); //if can't figure out timer do double click
  textSize(15);
  text("*Press a key for a little suprise while playing", 15, 20);
  text("*Move mouse to avoid the asteroids", 15, 38);
  fill(232, 98, 82);
  stroke(232, 98, 82);
  ellipse(width/2, height/2 + 40, 50, 50);
  //use circle so the rocket doesn't get stuck in "no loop". it just so the user can press the screen to move the rocket away from the collision
  textSize(60);
  fill(255);
}
void draw(){
如果(游戏结束){
DrawGameOverScreen();
}否则{
DrawGame();
}
}
虚空游戏(){
背景(0,0230);
m=毫秒();
//当游戏重新启动时,游戏将在0秒而不是从
//上一场比赛
gameTime=millis()-startTime;
//以秒为单位显示时间
文本大小(60);
填充(232、98、82);
文本(游戏时间/1000、790、60);
//显示有关如何玩游戏的说明
填充(232、98、82);
文本大小(60);
文本大小(15);
文本(“*在播放时按下一个键以获得些许惊喜”,15、20);
文本(“*移动鼠标以避开小行星”,15、38);
rocket1.display();
rocket1.face();
//在小行星对象中循环并移动它们。
//即使数组为[100],也只能循环通过您希望看到的数组(numAsteroid)
对于(int i=0;i