Skip to content

Commit

Permalink
feat($api): getSlow
Browse files Browse the repository at this point in the history
  • Loading branch information
cstuncsik committed Sep 28, 2016
1 parent 4a79f6f commit 1e7680d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ loop.stop();
loop.getFps();
loop.getElapsedTime();
loop.setSlow(2);
loop.getSlow();
```

| | | |
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions examples/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/gameLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
};
}
}));

0 comments on commit 1e7680d

Please sign in to comment.