mirror of
https://gitlab.com/arnekeller/tunnel-racer.git
synced 2024-11-21 22:44:59 +00:00
Handle low FPS better
This commit is contained in:
parent
5f66862843
commit
a487890d83
@ -10,6 +10,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="info">Score: <span id="score">0</span></div>
|
<div id="info">Score: <span id="score">0</span></div>
|
||||||
<button id="start">Start</button>
|
<button id="start">Start</button>
|
||||||
|
<div id="version">Version 1.1</div>
|
||||||
|
|
||||||
<script src="./gyronorm.complete.min.js"></script>
|
<script src="./gyronorm.complete.min.js"></script>
|
||||||
<script src="./three.min.js"></script>
|
<script src="./three.min.js"></script>
|
||||||
|
12
game.js
12
game.js
@ -114,7 +114,7 @@ let running = false;
|
|||||||
const spheres = [];
|
const spheres = [];
|
||||||
// wall segments
|
// wall segments
|
||||||
const borders = [];
|
const borders = [];
|
||||||
let frameCount = 0;
|
let time = Date.now() / 1000.0;
|
||||||
|
|
||||||
function logger(text) {
|
function logger(text) {
|
||||||
console.log(text);
|
console.log(text);
|
||||||
@ -296,7 +296,6 @@ document.getElementById("start").onclick = () => {
|
|||||||
borders.length = 0;
|
borders.length = 0;
|
||||||
removed = 0;
|
removed = 0;
|
||||||
lastSpawned = 0;
|
lastSpawned = 0;
|
||||||
frameCount = 0;
|
|
||||||
camera.position.set(0, 10, 25);
|
camera.position.set(0, 10, 25);
|
||||||
camera.lookAt(scene.position);
|
camera.lookAt(scene.position);
|
||||||
running = true;
|
running = true;
|
||||||
@ -346,10 +345,13 @@ function onWindowResize() {
|
|||||||
// main render/update function called once per frame
|
// main render/update function called once per frame
|
||||||
function animate() {
|
function animate() {
|
||||||
|
|
||||||
|
let now = Date.now() / 1000.0;
|
||||||
|
let delta = now - time;
|
||||||
|
time = now;
|
||||||
|
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
|
||||||
uniforms.iTime.value = frameCount / 60.0;
|
uniforms.iTime.value += delta;
|
||||||
frameCount++;
|
|
||||||
|
|
||||||
if (running) {
|
if (running) {
|
||||||
|
|
||||||
@ -385,7 +387,7 @@ function animate() {
|
|||||||
if (running) {
|
if (running) {
|
||||||
|
|
||||||
// advance player position, increase speed, handle movement input
|
// advance player position, increase speed, handle movement input
|
||||||
camera.position.z -= 0.5 * speed;
|
camera.position.z -= 0.5 * speed * delta * 60.0;
|
||||||
speed += 0.01;
|
speed += 0.01;
|
||||||
if (!Number.isNaN(leftRightMove)) {
|
if (!Number.isNaN(leftRightMove)) {
|
||||||
camera.position.x += 0.1 * leftRightMove;
|
camera.position.x += 0.1 * leftRightMove;
|
||||||
|
Loading…
Reference in New Issue
Block a user