我可以向Libgdx添加动作吗?

时间:2016-06-29 17:45:04

标签: java android libgdx

我正在尝试为图片添加操作,但它无法正常工作。 是否允许为图像添加动作? 我尝试以这种方式旋转它并且它可以工作:

mainButtons.center.rotateBy(5);

中心是Image。 但是,当我尝试这种方式时,它无法正常工作:

mainButtons.center.addAction(Actions.rotateBy(5));

我在这里定义了图片:

public class MainButtons {
    public Viewport viewport;
    public Stage stage;
    public GameImages gameImages;

    public boolean centerPressed;

    public Image center;


    public OrthographicCamera camera;
    public static Table table;




    //Constructor.
    public MainButtons(SpriteBatch spriteBatch) {
        camera = new OrthographicCamera();
        viewport = new StretchViewport(KidTele.V_WIDTH,KidTele.V_HIEGH,camera);
        stage = new Stage(viewport, spriteBatch);

        defineCenter();
    }
    public void defineCenter()
    {
        center=gameImages.centerImage();
        center.setBounds(viewport.getWorldWidth()/5f,viewport.getWorldHeight()/3f,viewport.getWorldWidth()/1.5f,viewport.getWorldHeight()/3f);
        center.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                centerPressed = true;
                return true;
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {

                centerPressed = false;
            }
        });
        //center.setVisible(false);
        stage.addActor(center);
    }
}

并在此处致电:

public class PlayScreen implements Screen {

    @Override
    public void render(float delta) {

        update(delta);
        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        b2dr.render(world, gamecam.combined);
        game.batch.setProjectionMatrix(gamecam.combined);

        game.batch.begin();
        if(mainButtons.centerPressed) {
            mainButtons.center.addAction(Actions.rotateBy(5));
           // mainButtons.center.rotateBy(5);
        }

        game.batch.draw(background, 0, 0, gameport.getWorldWidth(), gameport.getWorldHeight());
        game.batch.end();
        mainButtons.draw();
    }
}

0 个答案:

没有答案