Processing 如何使这个矩形变慢?
矩形正在移动,当我单击时,它需要以0.1而不是3移动。我不知道如何对鼠标按下的部分进行编码,使其始终保持在0.1Processing 如何使这个矩形变慢?,processing,Processing,矩形正在移动,当我单击时,它需要以0.1而不是3移动。我不知道如何对鼠标按下的部分进行编码,使其始终保持在0.1 float stripeX = 0; void setup() { size(500, 300); } void draw() { background(255); fill(10, 10, 100); rect(stripeX, 90, 150, 250); stripeX = stripeX + 3; stripeX
float stripeX = 0;
void setup() {
size(500, 300);
}
void draw() {
background(255);
fill(10, 10, 100);
rect(stripeX, 90, 150, 250);
stripeX = stripeX + 3;
stripeX = stripeX % width;
}
void mousePressed() {
stripeX = stripeX - 2.9;
}
这一切都有点冒险。抽签的频率是多少?在每一帧上?一般来说,在绘图函数中调整内容是个坏主意,它应该只是绘图 有点不对劲
float stripeX = 0;
float deltaX = 3.0;
void draw()
{
//omitted some code
stripeX += deltaX;
}
void mousePressed()
{
if(deltaX > 0.1)
deltaX = 0.1;
else
deltaX = 3.0; // let a second press put it back to 3.0
}
然而,你可能想把它放回3.0在鼠标上。你没有
提供足够的信息以了解如何拦截该事件。您可以在draw函数中使用mousePressed变量和if语句:
float-stripeX=0;
无效设置{
500、300号;
}
抽真空{
背景255;
填充10,10,100;
直肠条带,90150250;
如果鼠标按下{
stripeX=stripeX+.1;
}
否则{
stripeX=stripeX+3;
}
stripeX=stripeX%宽度;
}
在您的情况下,最好的方法是使用mouseReleased方法:
float stripeX, deltaX;
void setup() {
size(500, 300);
stripeX = 0f; // init values here, in setup()
deltaX = 3f;
}
void draw() {
background(255);
fill(10, 10, 100);
rect(stripeX, 90, 150, 250);
stripeX += deltaX;
stripeX = stripeX % width;
}
void mousePressed(){
deltaX = 0.1;
}
void mouseReleased(){
deltaX = 3f;
}