I asked a question like 4 days ago. Got some help and now my code looks like
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(); }
But it still does not work properly. He does the action once and stops. When I need to go in cycles. From blue to gold, then from gold to blue. I would really appreciate any help because I am just learning libGDX. Thanks.
I read all the answers and edited my code, but it still doesn't work:
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); }
Here is the 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(); }
Now it does not change color, it is always blue.
source share