My code does not work correctly. SurfaceView shows a black screen instead of Bitmaps. I make a game loop that doesn't depend on CPU, like Fix Your Timestep!, but I can't get it to work.
public class DrawView extends SurfaceView implements SurfaceHolder.Callback { private DrawThreat drawThread; public Background background; private int height; private int width; public DrawView(Context context) { super(context); getHolder().addCallback(this); drawThread = new DrawThreat(getHolder(), this); setFocusable(true); } @Override public void surfaceCreated(SurfaceHolder holder) { Rect surface = getHolder().getSurfaceFrame(); this.width = surface.width(); this.height = surface.height(); Bitmap back= BitmapFactory.decodeResource(App.getContext().getResources(), R.drawable.fon); back = Bitmap.createScaledBitmap(back, width, height, false); background = new Background(back, back, 0, 0, 0, -height); drawThread = new DrawThreat(getHolder(), this); drawThread.start(); } public class DrawThreat extends Thread { private final DrawView drawView; private SurfaceHolder surfaceHolder; private boolean running=true; private static final int UPDATES_PER_SECOND = 25; private static final int UPDATE_INTERVAL = 1000 / UPDATES_PER_SECOND * 1000000; private static final int MAX_FRAMESKIP = 5; private long nextUpdate = System.nanoTime(); public DrawThreat(SurfaceHolder surfaceHolder, DrawView drawView){ super(); this.surfaceHolder = surfaceHolder; this.drawView = drawView; } Tried to implement a game loop, but only a black screen is displayed
@Override public void run(){ while (running){ Canvas canvas = surfaceHolder.lockCanvas(); int skippedFrames = 0; while (System.nanoTime() > this.nextUpdate && skippedFrames < MAX_FRAMESKIP) { long delta = UPDATE_INTERVAL; this.drawView.update(delta); this.nextUpdate += UPDATE_INTERVAL; skippedFrames++; } double interpolation = (System.nanoTime() + UPDATE_INTERVAL - this.nextUpdate) / (double) UPDATE_INTERVAL; this.drawView.draw(canvas); surfaceHolder.unlockCanvasAndPost(canvas); } } } ```