【发布时间】:2024-01-09 23:45:01
【问题描述】:
我想将动画委托给不同的类/实体,以便渲染方法不会因动画所需的代码而臃肿。如果动画正在进行渲染方法应该执行该动画并在动画完成后移动到其正常处理。动画应该除了动画中涉及的必需精灵。 render 方法应该以正常方式渲染其他精灵。 (我说的是几个精灵的动画,而不是精灵表的精灵动画)
有没有面向对象的方式来实现这一点?
@Override
public void render ()
{
long ctime = System.currentTimeMillis();
Gdx.gl.glClearColor(backColor.r, backColor.g, backColor.b, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
float deltaTime = Gdx.graphics.getDeltaTime();
if(!startGame)
return;
if(camera != null)
batch.setProjectionMatrix(camera.combined);
batch.begin();
for (int i = 0; i < clusterList.size(); i++) {
clusterList.get(i).render(batch);
batch.end();
if(!isFinished)
scoreBar.setDeltaTime(deltaTime);
Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
shapeRenderer.setColor(Color.GRAY.r,Color.GRAY.g, Color.GRAY.b, 0.6f);
shapeRenderer.rect(0, camH - barHeight, camW, barHeight);
shapeRenderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
batch.begin();
scoreBar.render(batch);
if (animateSpread) {
timeLoopSpread += deltaTime;
if (timeLoopSpread > duration) {
timeLoopSpread = 0;
animateSpread = false;
} else
animateCluster();
}
}
private void animateCluster() {
float factor = Interpolation.pow5Out.apply(timeLoopSpread /duration);
for (int index =0; index < clusterList.size(); index++) {
Cluster tempC = clusterList.get(index);
currentPos.set(tempC.endPos);
currentPos.sub(tempC.startPos);
currentPos.scl(factor);
currentPos.add(tempC.startPos);
tempC.setCenterPosition(currentPos);
}
}
【问题讨论】: