|
@@ -15,7 +15,7 @@ class GameHandler
|
|
|
this.bDrawDebugFPS = val;
|
|
|
}
|
|
|
|
|
|
- static init()
|
|
|
+ static init(fps=60)
|
|
|
{
|
|
|
if (!this.renderMode) this.renderMode = RENDER_MODES.P2D;
|
|
|
switch (this.renderMode)
|
|
@@ -28,6 +28,7 @@ class GameHandler
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
+ frameRate(fps);
|
|
|
smooth();
|
|
|
}
|
|
|
|
|
@@ -42,10 +43,13 @@ class GameHandler
|
|
|
this.rootObjects.push(obj);
|
|
|
}
|
|
|
|
|
|
+ static prevMillis = 0;
|
|
|
+ static delta = 0;
|
|
|
static update()
|
|
|
{
|
|
|
+ this.delta = (millis() - this.prevMillis) / 1000;
|
|
|
for (let i = 0; i < this.rootObjects.length; i++)
|
|
|
- this.rootObjects[i].update(1 / frameRate());
|
|
|
+ this.rootObjects[i].update(this.delta);
|
|
|
}
|
|
|
|
|
|
static draw()
|
|
@@ -60,6 +64,7 @@ class GameHandler
|
|
|
}
|
|
|
|
|
|
for (let i = 0; i < this.rootObjects.length; i++)
|
|
|
- this.rootObjects[i].draw(1 / frameRate());
|
|
|
+ this.rootObjects[i].draw(this.delta);
|
|
|
+ this.prevMillis = millis();
|
|
|
}
|
|
|
}
|