Search code examples
javaandroidlibgdxgame-physics

addAction always rotates the actor origin 0,0, why?


My code (libgdx):

@Override
public void create () {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);

    texture = new Texture(Gdx.files.internal("image.png"));
    TextureRegion region = new TextureRegion(texture,256,128);

    Image actor = new Image(region);
    actor.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
    actor.setOrigin(actor.getWidth()/2, actor.getHeight()/2);

    group = new Group();
    group.addActor(actor);
    stage.addActor(group);

}

@Override
public void render () {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    stage.act(Gdx.graphics.getDeltaTime());
    stage.draw();


    if(Gdx.input.isButtonPressed(Input.Buttons.LEFT)){
        if(Gdx.input.getX() < Gdx.graphics.getWidth() / 2)
        {
            group.addAction(parallel(rotateBy(1,1)));
        }
        else
        {
            group.addAction(parallel(rotateBy(-1,1)));
        }
    }
}

Hi, i use LibGdx and my problem is that I would like to rotate on the same object , but when I start the rotation , I turn around point 0.0 in the lower left.

enter image description here

I can not understand why ... someone can explain how to do ?

Thank You


Solution

  • you're rotating the group not the actor so try this set the origin of the group to group.setOrigin(group.getWidth()/2, group.getHeight()/2);