refactor: animation frame

This commit is contained in:
cha0s 2019-03-28 12:45:22 -05:00
parent dbf226ba90
commit 14fe561c42

View File

@ -5,6 +5,7 @@ import {Container, Renderer} from '@avocado/graphics';
import {World} from '@avocado/physics/matter/world';
import {StateSynchronizer} from '@avocado/state';
import {Room, RoomView} from '@avocado/topdown';
import {clearAnimation, setAnimation} from '@avocado/timing';
const renderer = new Renderer([640, 360]);
const stage = new Container();
@ -94,13 +95,14 @@ function render() {
renderer.render(stage);
dirty = false;
}
const renderHandle = setInterval(render, 1000 / 60);
const renderHandle = setAnimation(render);
// Hot reloading.
if (module.hot) {
module.hot.accept((error) => {
console.error(error);
});
module.hot.dispose(() => {
clearAnimation(renderHandle);
room.destroy();
appNode.removeChild(renderer.element);
stage.destroy();