Skip to content

Commit

Permalink
fix(gameLoop): emit tick event every update
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Apr 6, 2024
1 parent 885af01 commit d3da95a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gameLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ export default function GameLoop({
return;
}

emit('tick');
accumulator += dt;

while (accumulator >= delta) {
emit('tick');
loop.update(step);

accumulator -= delta;
Expand Down
13 changes: 13 additions & 0 deletions test/unit/gameLoop.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ describe('gameLoop', () => {
expect(spy.called).to.be.true;
});

it('should emit the tick event for each loop update', () => {
let spy = sinon.spy();
on('tick', spy);

loop = GameLoop({
render: noop
});
loop._last = performance.now() - 2001 / 60;
loop._frame();

expect(spy.calledTwice).to.be.true;
});

it('should not update if page is blurred', done => {
loop = GameLoop({
update() {
Expand Down

0 comments on commit d3da95a

Please sign in to comment.