当前位置:  开发笔记 > 编程语言 > 正文

无法循环操作.libGDX

如何解决《无法循环操作.libGDX》经验,为你挑选了0个好方法。

我问过4天前的问题.得到了一些帮助,现在我的代码看起来像

ColorAction actionBtG = new ColorAction();
ColorAction actionGtB = new ColorAction();
SequenceAction sequenceAction;
RepeatAction repeatAction = new RepeatAction();
ShapeRenderer shapeRenderer;
Color blue = new Color(Color.BLUE);

@Override
public void create () {

    shapeRenderer = new ShapeRenderer();
    actionBtG.setColor(blue);
    actionBtG.setEndColor(Color.GOLD);
    actionBtG.setDuration(5);

    actionGtB.setColor(blue);
    actionGtB.setEndColor(Color.BLUE);
    actionGtB.setDuration(5);
    sequenceAction = new sequenceAction(actionBtG,actionGtB);






    repeatAction = new RepeatAction():        
    repeatAction.setAction(sequenceAction);
    repeatAction.setCount(RepeatAction.FOREVER);
}

@Override
public void render () {

    repeatAction.act(Gdx.graphics.getDeltaTime());
    Gdx.gl.glClearColor(1,1,1,1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    shapeRenderer.setColor(blue);
    shapeRenderer.rect(100, 100, 40, 40);
    shapeRenderer.end();


}

但它仍然有效.它会动作一次并停止.当我需要循环时.从蓝色到金色,然后从金色到蓝色.我真的很感激任何帮助,因为我只是在学习libGDX.谢谢.

我已经阅读了所有答案并编辑了我的代码,但它仍然无效:

private Actor actionManager = new Actor();
ColorAction actionBtG = new ColorAction();
ColorAction actionGtB = new ColorAction();
SequenceAction sequenceAction;
RepeatAction repeatAction;
Color activeColor = new Color(Color.BLUE);
ShapeRenderer shapeRenderer;


@Override
public void create () {

    shapeRenderer = new ShapeRenderer();
    actionBtG.setColor(activeColor);
    actionBtG.setEndColor(Color.GOLD);
    actionBtG.setDuration(5);

    actionGtB.setColor(activeColor);
    actionGtB.setEndColor(Color.BLUE);
    actionGtB.setDuration(5);
    sequenceAction = new SequenceAction(actionBtG,actionGtB);
    repeatAction = new RepeatAction();
    repeatAction.setAction(sequenceAction);
    repeatAction.setCount(RepeatAction.FOREVER);

    actionManager.addAction(repeatAction);
}

这是render()

@Override
    public void render () {
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    actionManager.act(Gdx.graphics.getDeltaTime());

    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    shapeRenderer.setColor(blue);
    shapeRenderer.rect(100, 100, 40, 40);
    shapeRenderer.end();
}

现在它不会改变颜色,它总是蓝色的.

推荐阅读
mobiledu2402851323
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有