【发布时间】:2016-04-11 06:48:14
【问题描述】:
我在 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);
}
这里是渲染()
@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();
}
现在它没有改变颜色,它总是蓝色的。
【问题讨论】:
-
set the target 的
Action在哪里? -
@user2016436 如果您在 ColorActions 上使用
setColor,则它们不需要目标。 -
最好将
blue重命名为其他名称,因为您不打算让它保持蓝色。 -
您是否忘记更新
shapeRenderer.setColor中的颜色名称,或者这只是您在上面粘贴的代码中的拼写错误?我没有看到任何其他错误。 -
在我的项目中 - 没关系,我只是将上面的代码复制粘贴了两次并在此处进行了编辑。
标签: java android libgdx scene2d