I want to make the movement to be independent from speed of game. I mean if my game UPS is 60 or 30 speed of game object will be the same. If UPS is 60, then for one second player moves 60 ticks * (speed / 60) pixels per tick. Or if UPS is 30, then for one second player moves 30 ticks * (speed / 30) pixels per tick. Distances are the same. I use this approach in my game.
public class Bullet extends GameObject {
private double vx, vy, g;
public Bullet(double x, double y, double vx, double vy) {
this.vx = vx;
this.vy = vy;
setX(x);
setY(y);
g = 8.0 / GameContainer.getUPS();
}
public void tick() {
setX(getX() + vx);
setY(getY() + vy);
vy += g;
}
public void render(Graphics2D g) {
g.setColor(new Color(255, 128, 0));
g.fillOval((int) getX(), (int) getY(), 4, 4);
}
}
Player's movement is fine. But when I change my UPS game ball's speed changes.
https://imgur.com/a/UePTqv3