Created
November 10, 2020 00:00
-
-
Save AlabasterAxe/91f4156c105b0f54daa6c8420f73d90d to your computer and use it in GitHub Desktop.
Updating the dinosaur's displacement and velocity in update()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @override | |
| void update(Duration lastTime, Duration elapsedTime) { | |
| double elapsedSeconds = | |
| ((elapsedTime.inMilliseconds - lastTime.inMilliseconds) / 1000); | |
| dispY += velY * elapsedSeconds; | |
| if (dispY <= 0) { | |
| dispY = 0; | |
| velY = 0; | |
| } else { | |
| velY -= GRAVITY_PPSPS * elapsedSeconds; | |
| } | |
| frame = (elapsedTime.inMilliseconds / 100).floor() % 2 + 3 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment