Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private long previousTime = System.currentTimeMillis();
- private long currentTime = previousTime;
- public void updateGame()
- {
- currentTime = System.currentTimeMillis();
- float elapsedSeconds = (currentTime - previousTime) / 1000f;
- foreach(GameObject gameObject in gameObjects)
- {
- // Apply gravity to velocity vector
- gameObject.velocity.y += (gravityConstant * elapsedSeconds);
- // Move objects x/y position based off it's velocity vector
- gameObject.position.x += (gameObject.velocity.x * elapsedSeconds);
- gameObject.position.y += (gameObject.velocity.y * elapsedSeconds);
- }
- checkCollisions();
- previousTime = currentTime;
- }
Add Comment
Please, Sign In to add comment