我在使用 Artemis 框架的 LibGDX 中实现流畅的慢动作渲染时遇到了问题。我了解如何更改“增量”以使其工作(使用 this ),但我无法弄清楚如何在 Screen
接口(interface)的渲染方法中实际实现它。如何更改 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用于呈现实体。
最佳答案
有一个 float :
public float speed = 0.5F; //half for example
在你的渲染方法中,只需将你的增量乘以它:
@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();
}
关于java - 使用 LibGDX 实现慢动作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20767109/