【问题标题】:addAction always rotates the actor origin 0,0, why?addAction 总是将actor原点旋转0,0,为什么?
【发布时间】:2015-03-18 14:33:21
【问题描述】:

我的代码(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)));
        }
    }
}

您好,我使用的是 LibGdx,我的问题是我想在同一个对象上旋转,但是当我开始旋转时,我绕左下角的 0.0 点转。

我不明白为什么... 有人可以解释一下怎么做吗?

谢谢

【问题讨论】:

    标签: java android libgdx game-physics


    【解决方案1】:

    你轮换的是组而不是演员 所以试试这个 将组的原点设置为 group.setOrigin(group.getWidth()/2, group.getHeight()/2);

    【讨论】:

      【解决方案2】:

      该组的 9 月来源不是您将组添加到此案例的演员:

          group.addActor(actor);
      
          group.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
          group.setOrigin(group.getWidth()/2, group.getHeight()/2);
      
          stage.addActor(group);
      

      其次,那个 API 正在使用?或者是您创建的方法,parallel 或 rotateBy,无论如何您都可以使用这个har为您工作。

      group.addAction(Actions.parallel(Actions.rotateBy(1,1)));
      

      P.S:如果有效,我的第一个答案是 Kareem Hammad 的回复,哈哈,但已经发表了。

      【讨论】:

        猜你喜欢
        • 2016-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-09
        • 1970-01-01
        • 2012-02-24
        • 2016-05-23
        • 2013-10-26
        相关资源
        最近更新 更多