Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : function interrupt draw

$
0
0
You haven't coded a way to check & restrict minimum & maximum values for variable speed.
So a user of your app has free rein to bug it in a matter of key presses! 

Here's your function keyPressed() w/ additional check for speed:
    final static float minSpd = .1, maxSpd = 10;
    final static float incSpd = .1;
    
    void keyPressed() {
    
      if (keyCode == LEFT)         speed -= incSpd;
      else if (keyCode == RIGHT)   speed += incSpd;
    
      if (speed < minSpd)          speed = minSpd;
      else if (speed > maxSpd)     speed = maxSpd;
    }
    


Viewing all articles
Browse latest Browse all 1768

Trending Articles