From 1e7680da56123997b0088e7748ea71ea0fea515d Mon Sep 17 00:00:00 2001 From: cstuncsik Date: Wed, 28 Sep 2016 06:19:52 +0200 Subject: [PATCH] feat($api): getSlow --- README.md | 2 ++ examples/index.html | 2 +- examples/main.js | 4 ++-- src/gameLoop.js | 12 +++++++++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4a07d49..3d67729 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ loop.stop(); loop.getFps(); loop.getElapsedTime(); loop.setSlow(2); +loop.getSlow(); ``` | | | | @@ -83,6 +84,7 @@ loop.setSlow(2); | **getFps** | Function | *Get FPS* | | **getElapsedTime** | Function | *Get elapsed time* | | **setSlow** | Function(slow:Number) | *Set slow motion coefficient* | +| **getSlow** | Function | *Get slow motion coefficient* | #### Inspiring blogs, posts diff --git a/examples/index.html b/examples/index.html index 062a938..30cd0ce 100644 --- a/examples/index.html +++ b/examples/index.html @@ -38,7 +38,7 @@ var box = document.getElementById('box'), prevBoxRotation = 0, currBoxRotation = 0, - velocity = 5, + velocity = 0.05, direction = 1, mouseDown = false, fpsDisplay = document.getElementById('fpsDisplay'), diff --git a/examples/main.js b/examples/main.js index f266160..0dbe3f8 100644 --- a/examples/main.js +++ b/examples/main.js @@ -3,14 +3,14 @@ requirejs(['../src/gameLoop'], function (createLoop) { var box = document.getElementById('box'), prevBoxRotation = 0, currBoxRotation = 0, - velocity = 5, + velocity = 0.05, direction = 1, mouseDown = false, fpsDisplay = document.getElementById('fpsDisplay'), elapsedTimeDisplay = document.getElementById('elapsedTimeDisplay'); var loop = createLoop({ - updateTimeStep: 1000 / 30, + updateTimeStep: 1000 / 60, input: input, update: update, render: render diff --git a/src/gameLoop.js b/src/gameLoop.js index 1b7b123..9a28ab8 100644 --- a/src/gameLoop.js +++ b/src/gameLoop.js @@ -38,7 +38,7 @@ lag += Math.min(sec, delta); while (lag >= slowStep) { lag -= slowStep; - update(updateTimeStep / slowStep); + update(updateTimeStep); } frameTime += (delta - frameTime) / fpsFilterStrength; render(lag / slowStep); @@ -65,16 +65,22 @@ return (then - beginning) / sec; } - function setSlow(slow) { + function setSlow(s) { + slow = s; slowStep = slow * updateTimeStep; } + function getSlow() { + return slow; + } + return { start: start, stop: stop, getFps: getFps, getElapsedTime: getElapsedTime, - setSlow: setSlow + setSlow: setSlow, + getSlow: getSlow }; } }));