/** * Returns the number of milliseconds that have elapsed since the game started. */ public static int tick() { return platform.tick(); }
private void onFrame () { int nextUpdate = this.nextUpdate; int updateTick = plat.tick(); if (updateTick >= nextUpdate) { int updateRate = this.updateRate; int updates = 0; while (updateTick >= nextUpdate) { nextUpdate += updateRate; updates++; } this.nextUpdate = nextUpdate; int updateDt = updates*updateRate; updateClock.tick += updateDt; updateClock.dt = updateDt; update(updateClock); } int paintTick = plat.tick(); paintClock.dt = paintTick - paintClock.tick; paintClock.tick = paintTick; paintClock.alpha = 1 - (nextUpdate - paintTick) / (float)updateRate; paint(paintClock); } }
private void onFrame () { int nextUpdate = this.nextUpdate; int updateTick = plat.tick(); if (updateTick >= nextUpdate) { int updateRate = this.updateRate; int updates = 0; while (updateTick >= nextUpdate) { nextUpdate += updateRate; updates++; } this.nextUpdate = nextUpdate; int updateDt = updates*updateRate; updateClock.tick += updateDt; updateClock.dt = updateDt; update(updateClock); } int paintTick = plat.tick(); paintClock.dt = paintTick - paintClock.tick; paintClock.tick = paintTick; paintClock.alpha = 1 - (nextUpdate - paintTick) / (float)updateRate; paint(paintClock); } }