Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit a50338f

Browse files
authored
Merge pull request #31 from brkyldz/master
fixed GameLoop stop function
2 parents 544a0c7 + d847fce commit a50338f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/native/utils/game-loop.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ export default class GameLoop {
1616
}
1717
}
1818
stop() {
19-
window.cancelAnimationFrame(this.loop);
19+
if (!this.loopID) {
20+
window.cancelAnimationFrame(this.loopID);
21+
this.loopID = null;
22+
}
2023
}
2124
subscribe(callback) {
2225
return this.subscribers.push(callback);
2326
}
2427
unsubscribe(id) {
25-
delete this.subscribers[id - 1];
28+
this.subscribers.splice((id - 1), 1);
2629
}
2730
}

src/utils/game-loop.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ export default class GameLoop {
1616
}
1717
}
1818
stop() {
19-
window.cancelAnimationFrame(this.loopID);
19+
if (!this.loopID) {
20+
window.cancelAnimationFrame(this.loopID);
21+
this.loopID = null;
22+
}
2023
}
2124
subscribe(callback) {
2225
return this.subscribers.push(callback);
2326
}
2427
unsubscribe(id) {
25-
delete this.subscribers[id - 1];
28+
this.subscribers.splice((id - 1), 1);
2629
}
2730
}

0 commit comments

Comments
 (0)