0
\$\begingroup\$

Could you suggest an implementation of a game loop with interpolation for SurfaceView and thread?

i have this, but it doesnt work.

while( running ) {
        Canvas canvas = null;

        loops = 0;
        while (System.currentTimeMillis() > next_game_tick
                && loops < MAX_FRAMESKIP) {


            player.getInfo(towardPointX, uiClicked);

            Collision(all_cars);
            running = player.isGameOn();

            next_game_tick += SKIP_TICKS;
            loops++;
        }

        interpolation = (System.currentTimeMillis() + SKIP_TICKS - next_game_tick
                / (double) SKIP_TICKS);
        background1.update(interpolation);
        moveCars(all_cars, interpolation);
        canvas = surfaceHolder.lockCanvas();
        background1.draw(canvas);
        canvasDraw(canvas,all_cars);
        surfaceHolder.unlockCanvasAndPost(canvas);

    }}}
```
\$\endgroup\$
2
  • \$\begingroup\$ How does the behaviour of this code differ from what you want/expect? \$\endgroup\$
    – DMGregory
    Apr 20 at 16:35
  • \$\begingroup\$ @DMGregory This code does not update the canvas, there is only a black screen on the screen. And i don't quite understand where the position calculations should be made and where the images are displayed on the canvas \$\endgroup\$
    – Limpan
    Apr 20 at 16:45

0

You must log in to answer this question.

Browse other questions tagged .