1
\$\begingroup\$

Have problems with rendering moving character using ShapeRenderer, it twitches while moving, and I don't understand where from comes the problem - bad game structure (do I need to override draw method from my actor,or just draw all entities in Stage's draw method) or troubles with movement logic.I'll add information if needed.

MainClass:

public class MFightGame extends Game {

@Override
public void create() {
    setScreen(new GameScreen());
}

@Override
public void render() {
    super.render();
}}

GameScreen:

public class GameScreen implements Screen {

private GameStage stage;

@Override
public void show() {
    stage = new GameStage();
}

public GameScreen() {

}

@Override
public void render(float delta) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.draw();
    stage.act(delta);
}

@Override
public void resize(int width, int height) {
    // TODO Auto-generated method stub
}

@Override
public void pause() {
    // TODO Auto-generated method stub
}

@Override
public void resume() {
    // TODO Auto-generated method stub
}

@Override
public void hide() {
    // TODO Auto-generated method stub
}

@Override
public void dispose() {
    // TODO Auto-generated method stub
}}

GameStage:

public class GameStage extends Stage {
private Creature creature;
private final float TIME_STEP = 1 / 300f;
private float accumulator = 0f;
private ShapeRenderer renderer;
private OrthographicCamera camera;

public GameStage() {
    creature = new Creature(100,100);
    addActor(creature);

    camera = new OrthographicCamera(800, 600);
    camera.position.set(camera.viewportWidth / 2f,
            camera.viewportHeight / 2f, 0);
    camera.update();
    renderer = new ShapeRenderer();
    renderer.setProjectionMatrix(camera.combined);
    Gdx.input.setInputProcessor(new InputHandler(creature));

}

@Override
public void act(float delta) {
    super.act(delta);
    accumulator += delta;
    while (accumulator >= delta) {
        accumulator -= TIME_STEP;
    }
}}
\$\endgroup\$
0
\$\begingroup\$

Usually, when you want to move an actor, you use an static value (speed) and delta together to calculate the distance move in that Loop/Frame.

I´ve never used Stage before, so I might be wrong, but I see you are using

accumulator += delta;

I would suggest using something like this:

accumulator = accumulator + (speed * delta); //speed being a pre-defined value.

"float delta" value can be totally different in each loop, with this method you reduce that difference effect on the movement.

I might be making a mistake, as I said, I´ve never used Stage, although I have used libGDX before, and that is how I always calculate movement on my games.

\$\endgroup\$
0
\$\begingroup\$

Disabling vertical synchronization solved my problem, movement become smooth.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .