使用LibGDX实现慢动作

时间:2013-12-24 21:51:20

标签: java libgdx

我无法使用Artemis框架在LibGDX中实现平滑的慢动作渲染。我理解如何更改“delta”以使其工作(使用this),但我无法弄清楚如何在Screen接口的render方法中实际实现它。如何更改Screen渲染方法的delta参数以显着减慢时间?

我的屏幕类:

public class GameScreen implements Screen {

    private SpriteRenderSystem spriteRenderSystem;
    private OrthographicCamera camera;
    private Game game;
    private World world;
    private Random r = new Random();

    public GameScreen(Game game){
        camera = new OrthographicCamera();
        camera.setToOrtho(false, 640, 480);
        this.game = game;

        world = new World();
        world.setManager(new GroupManager());

        spriteRenderSystem = world.setSystem(new SpriteRenderSystem(camera), true);
        world.setSystem(new VelocitySystem());
        world.setSystem(new AccelerationSystem());
        world.setSystem(new CollisionSystem());
        world.setSystem(new ExpirationSystem());

        world.initialize();

        for(int i = 0; i < 40; i += 4){
            EntityFactory.createBlock(world, i*16, 0, "tiles/water").addToWorld();
            EntityFactory.createBlock(world, (i+1) * 16, 0, "tiles/grass").addToWorld();
            EntityFactory.createBlock(world, (i+2) * 16, 0, "tiles/mud").addToWorld();
            EntityFactory.createBlock(world, (i+3) * 16, 0, "tiles/sand").addToWorld();
        }

        for(Entity e : EntityFactory.createExplosion(world, 320, 240)){
            e.addToWorld();
        }
    }

    @Override
    public void render(float delta) {
        // NEED HELP HERE
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        camera.update();
        world.setDelta(delta);
        world.process();
        spriteRenderSystem.process();
    }

    (...)
}

注意:我使用LibGDX + Artemis演示SpriteRenderSystem来渲染实体。

1 个答案:

答案 0 :(得分:2)

有一个浮动:

public float speed = 0.5F; //half for example

在你的渲染方法中,只需将你的delta乘以它:

@Override
public void render(float delta) {

    delta*=speed;  //<---

    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    camera.update();
    world.setDelta(delta);
    world.process();
    spriteRenderSystem.process();
}