libgdx后台延迟没有冻结

时间:2014-03-18 19:58:48

标签: android libgdx

我的游戏时间有些问题。玩我的游戏(link不会发布所有代码)到50分...管子保持关闭..为什么?

只有在鸟类产生的情况下,管子才会在游戏中打开,为什么?管子实际上只有1秒钟,我的代码有什么问题吗?

我最重要的文件是代码:SquishyBird/SquishyBird/src/com/CoreTek/squishybird/GameScreen.java

Seondly,  如何在后台触摸时设置延迟:touched -> door close -> 1sec -> door opens

虽然这个1 sec我游戏中的所有内容仍然应该移动,所以它不能是一个冻结延迟。我怎么能这样做?

可能错误就在这里:

    delayTime = TimeUtils.millis();

    if(Gdx.input.isTouched()){
        Assets.rect_pipe_down.y = 512 - 320/2 - 96;
        Assets.rect_pipe_up.y = -320 + 320/2 + 96;
        Assets.rect_hitbox.x = 288/2 - 52/2 + 2;            
    }

    if(TimeUtils.millis() - delayTime > 1000){
        Assets.rect_pipe_down.y = 512 - 320/2;
        Assets.rect_pipe_up.y = -320 + 320/2;
        Assets.rect_hitbox.x = 288/2 - 52/2 + 2 + 500;  
    }

我的整个渲染:

@Override
public void render(float delta){
    Gdx.gl.glClearColor(0F, 0F, 0F, 1F);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    camera.update();

    stateTime += Gdx.graphics.getDeltaTime();
    Assets.region_current_bird = Assets.animation_bird.getKeyFrame(stateTime, true);

    batch.setProjectionMatrix(camera.combined);

    batch.begin();
        batch.draw(Assets.region_bg, 0, 0);
        batch.draw(Assets.region_pipe_down, Assets.rect_pipe_down.x, Assets.rect_pipe_down.y);
        batch.draw(Assets.region_pipe_up, Assets.rect_pipe_up.x, Assets.rect_pipe_up.y);
        Assets.font_points.draw(batch, "Points: " + String.valueOf(points), 10, 512 - 10);
        for(Rectangle rect_bird: Assets.rect_birds_array){
            batch.draw(Assets.region_current_bird, rect_bird.x, rect_bird.y);
        }
    batch.end();

    if(Gdx.input.isTouched()){
        Assets.rect_pipe_down.y = 512 - 320/2 - 96;
        Assets.rect_pipe_up.y = -320 + 320/2 + 96;
        Assets.rect_hitbox.x = 288/2 - 52/2 + 2;            
    }

    if(TimeUtils.millis() - delayTime > 1000){
        Assets.rect_pipe_down.y = 512 - 320/2;
        Assets.rect_pipe_up.y = -320 + 320/2;
        Assets.rect_hitbox.x = 288/2 - 52/2 + 2 + 500;  
    }

    if(TimeUtils.millis() - lastSpawnTime > spawnTime) spawnBirds();

    Iterator<Rectangle> iter = Assets.rect_birds_array.iterator();
    while(iter.hasNext()){
        Rectangle bird = iter.next();
        bird.x += 200 * Gdx.graphics.getDeltaTime();
        if(bird.x - 34 > 288) iter.remove();
        if(bird.overlaps(Assets.rect_hitbox)){
            points++;
            if(spawnTime > 10){
                spawnTime-=10;
            }
            iter.remove();
        }
    }
}

0 个答案:

没有答案