Reputation: 3417
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.
I can not understand why ... someone can explain how to do ?
Thank You
Upvotes: 1
Views: 73
Reputation: 21728
September origin of the group not the actor you add the group to this case:
group.addActor(actor);
group.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
group.setOrigin(group.getWidth()/2, group.getHeight()/2);
stage.addActor(group);
secondly, that API're using? or is the method, parallel or rotateBy created by you, anyway you can use this haver works for you as you pretend.
group.addAction(Actions.parallel(Actions.rotateBy(1,1)));
P.S: if it works, the response of Kareem Hammad was my first answer, haha, but already had published.
Upvotes: 1
Reputation: 36
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);
Upvotes: 2