Game performance

I reduced my slowdown to this method

public void drawMap(Canvas canvas) {

    if (car.x > 0 && map != null) {
        clipArea = Bitmap.createBitmap(map, mapx, mapy, getWidth(),
                getHeight());
        canvas.drawBitmap(clipArea, 0, 0, null);
    }
}

It takes about 3 seconds! any help would be appreciated, the bitmap is about twice the size of the screen, but this is the key to my game, so I need to save this :) any help on optimization? thank

+3
source share
1 answer

you always wait for a fixed time here, no matter how long all calculations and updates ui take

 frame.postDelayed(frameUpdate, FRAME_RATE);

what you want to do: before the new "tick of the game" you create the variable timestamp, then you perform the calculations and then check how much time is left until the next tick.

something like that:

synchronized public void run() {


    Date timestamp = new Date();

    // do your calculations
    ...

    // calculate how much time it took and when the next update should be:
    int timeToNextTick = FRAME_RATE - (new Date().getTime() - timestamp.getTime());
    frame.postDelayed(frameUpdate, timeToNextTick);

}

, (, )

0

All Articles