Reputation: 988
Recently, I decided to make a new game and give that chance to libgdx framework. Long time ago, I used to make some games in Slick2D, and I remember that their approach when it comes to update(delta) and draw() object, was different, then now in libgdx which has only render(delta). So I came to idea, to abstract game, and make my own class Game and Screen with update & draw. However, now I'm in doubt regarding parameter delta from render method. Watching some examples on the internet regarding libgdx with implementation concept update and draw, people were passing delta parameter from render method to both update and draw methods. From this description, my questions are:
Upvotes: 0
Views: 263
Reputation: 1517
You could utilize LibGDX's Scene2d package:
https://github.com/libgdx/libgdx/wiki/Scene2d
The Stage class does provide separate act and draw methods. So the render() method in the Game class ends up looking like this:
@Override
public void render() {
Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
}
Upvotes: 0
Reputation: 8113
Note that just taking the delta time as-is can cause e.g. teleporting on hick-ups and is not discrete. Therefor it's usually a good idea to limit the value (e.g. delta = Math.min(delta, 1/30f);
). Using a fixed time step is often used when you need your game logic to be discrete.
Upvotes: 1