Javascript 处理循环 int objectX=width/2; int objectY=高度/2; int-snelheidY=1; 智力得分=0; int-richting=1; 内正平衡; int bal=椭圆(objectX,objectY,50,50); 丢失=错误; 无效设置(){ 尺寸(400400); positiebal=高度/2; 文本大小(12); } void draw(){ 背景(0,0,0); 椭圆(正平衡,目标,50,50); 如果(objectY>375) 斯内尔海迪=-斯内尔海迪; if(objectY

Javascript 处理循环 int objectX=width/2; int objectY=高度/2; int-snelheidY=1; 智力得分=0; int-richting=1; 内正平衡; int bal=椭圆(objectX,objectY,50,50); 丢失=错误; 无效设置(){ 尺寸(400400); positiebal=高度/2; 文本大小(12); } void draw(){ 背景(0,0,0); 椭圆(正平衡,目标,50,50); 如果(objectY>375) 斯内尔海迪=-斯内尔海迪; if(objectY,javascript,processing,Javascript,Processing,我不会为此使用loop()和noLoop()。相反,将您的状态存储在一组变量中,并使用这些变量绘制每个帧。下面是一个简单的示例: int objectX = width/2; int objectY = height/2; int snelheidY = 1; int score = 0; int richting = 1; int positiebal; int bal = ellipse(objectX, objectY, 50, 50); lost = false; vo

我不会为此使用
loop()
noLoop()
。相反,将您的状态存储在一组变量中,并使用这些变量绘制每个帧。下面是一个简单的示例:

int objectX = width/2; 
int objectY = height/2; 
int snelheidY = 1; 
int score = 0; 
int richting = 1; 
int positiebal;  
int bal = ellipse(objectX, objectY, 50, 50); 
lost = false;

void setup() { 
    size(400, 400); 
    positiebal = height/2; 
    textSize(12); 
} 

void draw() { 
    background(0, 0, 0); 
    ellipse(positiebal, objectY, 50, 50); 
    if(objectY > 375) 
        snelheidY = -snelheidY; 
    if(objectY<25) 
        snelheidY = -snelheidY; 
    objectY = objectY + snelheidY; 
    text("score = " +score,4,10); 

    if (score < 0)
        {  textSize(20); 
            text("play again",50,50);
            noLoop();
            lost = true;
            textSize = 13;
        }

    }

    void mousePressed() { 
        int distance = dist(200, objectY, mouseX, mouseY); 
        if (distance<=25) 
    //score hoger maken met 1 punt
{ score=score+1; 

    if (snelheidY < 0) 
        { snelheidY = snelheidY -1; } 
    { snelheidY = snelheidY+1; } 
} 
    // score met 1 punt lager maken
    else 
        { score = score - 1;

            if (snelheidY > 1)
                { snelheidY = snelheidY -1; } 


        }  

        if (lost == true)
            { snelheidY = 1;
                score = 0;
                positiebal = height/2;
                richting = 1;
                lost= false; 
                loop();}

            }

感谢您的帮助,但我们必须使用循环来解决问题,这是项目的一部分…@Beastmaster64您确定“使用循环解决问题”的意思是使用
loop
noLoop()
或者它可能意味着使用
进行
循环?如果您需要帮助,请发布一个而不是整个项目。因此这是一个学校项目?另外,
循环
noLoop
函数在哪里?@AndersTornblad请注意这是一个问题,
循环(
noLoop()
函数是处理函数。你知道这一点吗?
boolean start = true;
boolean play = false;
boolean end = false;

void draw() {

  background(0);

  if (start) {
    text("start", 20, 20);
  } else if (play) {
    text("play", 20, 20);
  } else if (end) {
    text("end", 20, 20);
  }
}

void mousePressed() {
  if (start) {
    start = false;
    play = true;
  } else if (play) {
    play = false;
    end = true;
  } else if (end) {
    end = false;
    start = true;
  }
}