We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have a problem using surface.setSize(). Here is a code example :
void setup(){
background(0);
surface.setSize(1000, 1000);
fill(255);
rect(10, 10, 10, 10);
}
void mouseClicked(){
surface.setSize(1000, 1000);
fill(255);
rect(10, 10, 10, 10);
}
void draw(){}
When starting the sketch, I only have the black windows, the rectangle doesn't appear. But when I click the mouse, the rectangle appears. If I change mouseClicked() like that :
void mouseClicked(){
surface.setSize(width + 1, height + 1);
fill(255);
rect(10, 10, 10, 10);
}
The windows becomes 1 pixel larger as expected but the white rectangle doesn't appear. I tried to do text(), to add delay() after surface.setSize() but it's the same.
Somebody knows how to fix this issue ?
Thanks.
Answers
Ok I found out my error. The surface.setSize() is done at next draw() loop.
@BriceFW -- Great! In general, if your draw loop is empty and being called, the drawing will be empty. So move all drawing code to draw(), or to something called by draw().
You can also control in-draw code with the variable mousePressed:
...but don't call surface.setSize in the draw loop directly or with continuous variables / functions like mousePressed / mousePressed() -- a stream of multiple resize commands can get stuck in a nasty loop.