@Override public void tick(int elapsed) { // micro-optimization to avoid repeated field reads int nextUpdate = this.nextUpdate, updateRate = this.updateRate; int updates = 0; while (elapsed >= nextUpdate) { nextUpdate += updateRate; updates++; } if (updates > 0) { update(updates*updateRate); // calling update() may have taken > 1ms, so we need to re-read the clock to accurately // report the fraction of time that has elapsed between updates elapsed = PlayN.tick(); } float alpha = 1 - (nextUpdate - elapsed) / (float)updateRate; paint(alpha); this.nextUpdate = nextUpdate; }