以下是我的代码的简要概述:
void setup() {...}
void draw() {
//Two images horizontal to each other blink alternately. //After 4 blinks function vertical_blink() is called
}
void vertical_blink() { //Two images blink vertically
}
问题是垂直图像永远不会闪烁。程序回到水平闪烁。如何使程序保持垂直闪烁?我试着延迟,而且为了。所有这些都弄乱了时机。代码在这里。
PImage water;
PImage waterh;
PImage home;
PImage homeh;
int t;
int flag = 0;
void setup() {
size(1800, 1128);
background(0);
home = loadImage("C:\\IoT\\SWSG\\FinalStages\\ProcessingPics\\home.jpg");
homeh = loadImage("C:\\IoT\\SWSG\\FinalStages\\ProcessingPics\\homeh.jpg");
water = loadImage("C:\\IoT\\SWSG\\FinalStages\\ProcessingPics\\water.jpg");
waterh = loadImage("C:\\IoT\\SWSG\\FinalStages\\ProcessingPics\\waterh.jpg");
t = millis() / 1000;
}
void draw() {
background(0);
image(home, 100, 25, 200, 200);
image(water, 350, 25, 200, 200);
if ((millis() / 1000) - t >= 3) {
flag++;
t = millis() / 1000;
}
if (flag == 0)
image(homeh, 100, 25, 200, 200);
if (flag == 1)
image(waterh, 350, 25, 200, 200);
if (flag == 2)
new_section();
}
void new_section() {
background(255);
int t2 = millis() / 1000, flag2 = 0;
image(home, 100, 25, 200, 200);
image(water, 100, 250, 200, 200);
if (millis() / 1000 - t2 >= 3) {
flag2++;
t2 = millis() / 1000;
}
if (flag2 == 0)
image(homeh, 100, 25, 200, 200);
if (flag2 == 1)
image(waterh, 100, 250, 200, 200);
if (flag2 == 2)
flag2 = 0;
}
答案 0 :(得分:0)
您是否尝试过使用frameCount
代替millis()
?所以你的柜台可能会喜欢这样的东西
void draw() {
if (frameCount % 4 == 0) {
// Called every 4 frames
}
if (frameCount % 4 == 2) {
// Called every 4 frames, but 2 frames offset
}
}