标签:java android libgdx scene2d
我问过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();
}
现在它不会改变颜色,它总是蓝色的.
解决方法:
您遇到了与期望与Actors一起使用的Actions相关的错误.很多Actions在没有Actor的情况下工作正常,但是SequenceAction没有,因为它希望附加到Actor以检测它是否应该仍在运行.
所以一个有点hacky的解决方案是在你设置它时为你的顶级动作添加一个虚拟actor.这模拟了当您向舞台中的actor添加动作时发生的情况.
repeatAction.setActor(new Actor());
如果您计划在应用中使用更多操作,则可以创建一个用于管理所有操作的Actor:
private Actor actionManager = new Actor();
//when creating actions:
actionManager.addAction(repeatAction);
//In render(), use this instead of calling act on individual actions
//It will call act on all actions in the actor:
actionManager.act(Gdx.graphics.getDeltaTime());
当然,如果你想使用舞台绘制东西,你可以简单地将你的动作添加到舞台而不是使用Actor作为你的动作管理器.
我个人觉得scene2d动作必须比UniversalTweenEngine更容易使用和设置.
标签:java,android,libgdx,scene2d 来源: https://codeday.me/bug/20190523/1156733.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。