so i tried to see your code
( old win7 PC firefox browser )
but
mySketch, tab2,tab3,tab4,tab5,tab7
look empty from here.
i think your project is damaged?
and using [1] player left [w][s] is usable,
possible the paddle too slow moving
( even frameRate print looks good )
check the details on while key pressed and if key pressed and released
Yeah i know that framerate and velocity are ok. I posted this question to get an answer - not more questions. Sorry kll - but if you don’t know what i could change that the ball runs smoother - why are you writing here?
I removed the push/pop matrix stuff in the draws of ball and paddle and replaced it with only rect(…). That didn’t help though.
The sketch runs at around 60 fps which should be more than enough to not stutter for the human eye.
If i reduce the velocity of the ball - it will fly slower and i don’t want that. Also the checks in the draw i need for the gameplay and also because i use it with the kinect. (Kinect code is removed in the sketch on openprocessing because they don’t have those libraries…)
Still - the ball doesn’t go really smooth but stutters a little bit. There must be something i’m missing. -.-
It isn’t that complicated. Right now, you move your paddle like this:
float moveAmount() {
float movement = 0;
if (up) {
movement += speed;
}
if (down) {
movement -= speed;
}
return movement;
}
You do this if the last frame took 1/60th of a second to draw or 1/2 second to draw. So if your framerate changes, the paddle speed changes. But what if instead you wrote:
movement += speed * 60 / frameRate();
If your target is 60fps (the default), then you want to know what ratio of that the last frame was. If the last frame was 60fps, multiply your speed by 1.0 (60/60). If the last frame was 30fps, multiply your speed by 2.0 (60/30). If the last frame was 120fps for some weird reason, multiply your speed by 0.5 (60/120).
Whatever your target fps is, set it with frameRate(target) and then use target/frameRate() to scale your motion offsets – for paddles, the ball, whatever.
Edit just realized you are using OpenProcessing, not p5.js. Outside p5.js frameRate() doesn’t return an inter-frame time for you – you will need to calculate that yourself.
If that wasn’t global, it might look something like this (untested):
float moveAmount() {
float fps = 1000.0/(millis()-lastmillis);
float movement = 0;
if (up) {
movement += speed * (60.0 / fps);
}
if (down) {
movement -= speed * (60.0 / fps);
}
lastmillis = millis();
return movement;
}
have you tried using lerp() function? you can achieve smooth movement of the paddles. PVector has a built-in lerp() method in it, or you can use general lerp() for general usability.