我问过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(); }
现在它不会改变颜色,它总是蓝色的.