TfGuy44's code worked really well!
But I did a slight modification (I think it is quite important):
When I release the button, friction works really well, but I noticed that the lines lag while slowing down just before completely stopping [scrolling becomes non smooth just before stopping], and this would have an unpleasant effect when scrolling readable text.
So I added one line of code that eliminates this problem:
Code: if( !upPressed && !downPressed )
{
if (abs(ver) < 0.22) ver = 0; // <---- This is the modification
ver*=.95;
}
I actually got the idea from Smitty's code [Thanks by the way :) ]
the value 0.22 seems good to me in this case.
Now, here is the text scrolling code I have now:
Code:boolean upPressed;
boolean downPressed;
float pos;
float ver;
float acc;
PFont font;
String s = "The quick brown fox jumped over the lazy dog.";
void setup(){
size(600,600);
pos = height/2.0;
ver = 0;
font = loadFont("Consolas-48.vlw");
textFont(font);
}
void draw(){
background(100);
acc = 0;
if( upPressed ){
acc+=0.1;
}
if( downPressed ){
acc-=0.1;
}
ver+=acc;
if( !upPressed && !downPressed )
{
if (abs(ver) < 0.22) ver = 0;
ver*=.95;
}
pos+=ver;
pos = constrain(pos,0,height);
text(s, 20, pos, 500, 500);
}
void keyPressed(){
if( key == CODED ){
if( keyCode == UP ){ upPressed = true; }
if( keyCode == DOWN ){ downPressed = true; }
}
}
void keyReleased(){
if( key == CODED ){
if( keyCode == UP ){ upPressed = false; }
if( keyCode == DOWN ){ downPressed = false; }
}
}
I guess I now have to modify the scrolling boundaries because the current ones won't work on long texts.
Thank you all!