I am trying to display text that can move around screen in an animated environment. To do this I am using a combination of rect() and text() to create the labels and scale() and translate() to fit contents on screen and allow zooming and panning.
The problem I have is that line and polygon locations seemed to be correct, but text placement seems to be subject to some kind of rounding, so it 'judders' as it moves. This can be demonstrated with a minimal example:
Code:
PFont font;
float pos=0;
float inc = 0.005;
float w,h;
float scaling = 10; // Change between 1 and 20 to see rounding effect.
void setup()
{
size(400, 100);
frameRate(10);
font = createFont("GillSans",12);
textFont(font, width/20);
textAlign(LEFT,TOP);
w = textWidth("Test");
h = textAscent();
}
void draw()
{
background(200,180,180);
textFont(font, width/(20*scaling));
strokeWeight(1/scaling);
float x = lerp(0,(width-w)/scaling,pos);
scale(scaling);
// Draw rectangle and text at the same location.
fill(255);
rect(x,height/(2*scaling),w/scaling,h/scaling);
fill(0);
text("Test",x,height/(2*scaling));
// Move label a little to the left or right.
pos += inc;
if (pos >=1) inc = -0.005;
if (pos <=0) inc = 0.005;
}
Am I missing something obvious here, or is there some workaround? Apologies if this has been covered elsewhere, but my limited searching skills have not dug up any obvious posts or bug reports.
Thanks,
Jo.