We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Rectangle flickers when moves
Page Index Toggle Pages: 1
Rectangle flickers when moves (Read 674 times)
Rectangle flickers when moves
Jul 3rd, 2008, 8:42am
 
Hi,
I want to make a rectangle move to the top and have it's size decreased.
The following program works, however, the animation is not smooth, and flickers a bit as the rectangle moves, both when only moving, and when moving+resizing. Adding smooth() doesn't help. I used linear transformation - maybe that's the problem?

Code:

void setup() {
size(580,580+100);
}
float x = 0.001;
int ms = 0,now;
void draw() {
now = millis();
background(255,0.5);
if (now > 1000*1) {
scale(1-x*0.8);
translate(0,-100*x);
x= min(x+0.01,1);
}
fill(#FF0000);
rect(0,100,580,580);
}
Re: Rectangle flickers when moves
Reply #1 - Jul 3rd, 2008, 5:17pm
 
If you're going to use a background with an alpha value, you need to use this Code:
createGraphics(); 

Re: Rectangle flickers when moves
Reply #2 - Jul 4th, 2008, 2:44pm
 
I don't see how createGraphics has anything to do with transparency. It seems to me that it should create images object I can manipulate.

Anyhow, it doesn't solve the ugly movement problem. Any idea?
Re: Rectangle flickers when moves
Reply #3 - Jul 5th, 2008, 6:50pm
 
My guess is that this is due to the fact that your screen and your gfx card arent snychronized ("vsynced").

If youre using opengl, putting this code in your setup() method might fix it:

Code:

GL gl = ((PGraphicsOpenGL)g).beginGL();
gl.setSwapInterval(1);
((PGraphicsOpenGL)g).endGL();
Re: Rectangle flickers when moves
Reply #4 - Jul 6th, 2008, 4:38pm
 
It seems that using openGL helps already. I used openGL and it looks MUCH better.

BTW, your code doesn't work for me. I used:

import processing.opengl.*;
...
size(580,580,OPENGL);
GL gl ...

and it says:
C:/DOCUME~1/IAF/LOCALS~1/Temp/build61535.tmp/Temporary_4476_4480.java:5:3:5:4: Semantic Error: Type "GL" was not found.

Thanks for your help though...
Re: Rectangle flickers when moves
Reply #5 - Jul 15th, 2008, 2:49pm
 
import javax.media.opengl.*;

might fix this
Page Index Toggle Pages: 1