我正在尝试处理,我为我的项目编写了一个非常简单的舞台系统。我有 3 个阶段:0 - 持续 2 秒,灰屏 1 - 持续 1 秒,从黑色过渡到白色 2 - 持续 2 秒,从白色过渡到黑色
阶段 1 和 2 一遍又一遍地重复,有时在任一阶段的最后一帧和下一阶段的第一帧之间重复,屏幕闪烁(我想你会自己看到)。
package ryby;
import java.awt.Color;
import processing.core.PApplet;
import processing.core.PImage;
public class Ryby extends PApplet {
public static PApplet APPLET;
public static final int X = 700;
public static final int Y = 465;
int counter;
int state = 0;
int substate = 0;
StringBuilder title = new StringBuilder();
@Override
public void setup() {
APPLET = this;
frameRate(60);
smooth();
size(X, Y, JAVA2D);
counter = millis();
}
@Override
public void draw() {
title.delete(0, title.length());
title.append("Ryby - ").append(state).append(" ").append(substate)
.append(" ").append(frameRate);
frame.setTitle(title.toString());
Color color = new Color(get(0, 0));
System.out.println(color);
switch (state) {
case 0:
intro();
break;
}
}
public static void main(String _args[]) {
PApplet.main(new String[]{ryby.Ryby.class.getName()});
}
void intro() {
System.out.println(substate);
System.out.println(millis() - counter);
switch (substate) {
case 0:
setSubState(2000, 1);
break;
case 1:
background((millis() - counter) * 255 / 1000);
setSubState(1000, 2);
break;
case 2:
background(255 - (millis() - counter) * 255 / 2000);
setSubState(2000, 1);
break;
}
}
void setState(int ms, int s) {
if (millis() >= counter + ms) {
state = s;
counter = millis();
}
}
void setSubState(int ms, int s) {
if (millis() >= counter + ms) {
substate = s;
counter = millis();
}
}
}
我知道我在某个地方犯了一个愚蠢的错误,我只需要找出在哪里:)