0

我使用这个类来更新渲染视图

public class AndroidFastRenderView extends SurfaceView implements Runnable {
    AndroidGame game;
    Bitmap framebuffer;
    Thread renderThread = null;
    SurfaceHolder holder;
    float speedRegulator= 100000009.9f;
    volatile boolean running = false;

    public AndroidFastRenderView(AndroidGame game, Bitmap framebuffer) {
        super(game);
        this.game = game;
        this.framebuffer = framebuffer;
        this.holder = getHolder();
    }

    public void resume() { 
        running = true;
        renderThread = new Thread(this);
        renderThread.start();         
    }      

    public void run() {
        Rect dstRect = new Rect();
        long startTime = System.nanoTime();
        while(running) {  
            if(!holder.getSurface().isValid())
                continue;           

            float deltaTime = (System.nanoTime()-startTime) /speedRegulator;
            startTime = System.nanoTime();

            game.getCurrentScreen().update(deltaTime);
            game.getCurrentScreen().present(deltaTime);

            Canvas canvas = holder.lockCanvas();
            canvas.getClipBounds(dstRect);
            canvas.drawBitmap(framebuffer, null, dstRect, null);                           
            holder.unlockCanvasAndPost(canvas);
        }
    }

    public void pause() {                        
        running = false;                        
        while(true) {
            try {
                renderThread.join();
                break;
            } catch (InterruptedException e) {
                // retry
            }
        }
    }        
}

号码:

float speedRegulator= 100000009.9f;

是允许我降低和提高播放器速度的参数,不幸的是如果我将它设置为浮动speedRegulator= 1000000000.0f;太慢,如果离开float speedRegulator= 100000009.9f;太快。

我该如何解决这个问题?为什么速度变化不是渐进的?

4

1 回答 1

0

这不是一个渐进的变化,因为1000000000.0f大约是十倍100000009.9f。如果您想加快速度(比如 10%),请尝试类似900000000.

于 2012-10-12T03:07:31.920 回答