使用LibGDX实现慢动作

3
我在使用LibGDX和Artemis框架实现平滑的慢动作渲染时遇到了麻烦。我知道如何更改“delta”以使其正常工作(使用这个),但我无法弄清楚如何在Screen接口的渲染方法中实际实现它。我该如何更改Screen的渲染方法的delta参数以基本上减缓时间?
我的Screen类:
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个回答

3

拥有一个浮动:

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();
}

我已经尝试过了。然而它似乎没有任何不同之处。这是因为GDX在读取覆盖的渲染方法之前使用未更改的delta进行渲染吗? - Siva Mahadevan
它应该可以工作。Libgdx本身不会渲染任何东西。它调用被覆盖的渲染方法,这就是正在执行的内容。如果您每步仅以0.5 delta更新游戏逻辑,则必须导致减速。 - noone

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接