@Override
        public void run() {
            long next_update = System.currentTimeMillis();
            long last_update = System.currentTimeMillis();
            int frames_skipped;
            float interpolation;
            long sleep_time;

            try {
                // Initialize the input devices:
                for (InputDevice device : inputDevices.values())
                    device.initialize();
                // Start the loop:
                while (isRunning){
                    // Enforce Max FPS boundary:
                    sleep_time = (last_update + FPS_WAIT_TICKS) - System.currentTimeMillis();
                    if (sleep_time > 0) Thread.sleep(sleep_time);
                    last_update = System.currentTimeMillis();
                    // Update game:
                    frames_skipped = 0;
                    while (System.currentTimeMillis() > next_update
                            && frames_skipped < MAX_FRAMESKIP){
                        // Check if scene changed and pause it:
                        if (!scene_id.equals(current_scene)){
                            scenes.get(scene_id).onPauseCall();
                            // Start the new scene:
                            Scene new_scene = scenes.get(current_scene);
                            startScene(new_scene);
                        }
                        // Update events of current scene:
                        updateGame( scenes.get(scene_id) );
                        // Schedule next update:
                        next_update += WAIT_TICKS;
                        frames_skipped++;
                    }
                    // Repaint game!
                    // Calculate interpolation for smooth animation between states:
                    interpolation = ((float)(System.currentTimeMillis() + WAIT_TICKS - next_update)) / ((float)WAIT_TICKS);
                    // Render-events:
                    Viewport.canvas.redraw(interpolation);
                }
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            } finally {
                // Release all InputDevices:
                for (InputDevice device : inputDevices.values())
                    device.release();
            }
        }