I've been dividing the increment by the FPS
Don't do that! Use a Timer
or a swing
Timer
to update everything at a constant rate. For example you could do something like this:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
public class Test {
public static void main(String[] args) throws InterruptedException {
Timer timer = new Timer(10,new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
updateProjectilePositions();
}
});
timer.start();
}
private static void updateProjectilePositions() {
// TODO Auto-generated method stub
}
}
Note that if you use a swing Timer
, your projectile updating will happen on the swing thread. If the updating hangs, your GUI will also hang.
You also should not call map.addEntity
inside paint()
since paint()
does one thing and one thing only: paint everything. You can get around this but mixing up the code that updates things like position with code that renders the objects will eventually bite you.