gpt4 book ai didi

java - LibGDX Actor 不会绘制 Action

转载 作者:行者123 更新时间:2023-11-30 07:12:19 25 4
gpt4 key购买 nike

我有以下 LibGDX Actor 子类,它似乎不执行任何视觉操作,但它执行延迟的可运行对象(我可以在预期延迟后看到所有 Gdx.app.log 消息)。

我在重写的 TileActor.act 方法中调用 super.act(delta),并且还调用 stage.act(); Stage 类中的 stage.draw()

这些 Actor 显示正常,所以唯一缺少的是缩放/淡入淡出的视觉 Action 。

如何调试这个?

class TileActor extends Actor {
private TileLogic logic;
private boolean flipped;
private enum AnimationState {
IDLE,
SCHEDULED,
PROGRESS,
COMPLETED
}
private AnimationState flippedAnimation;

private float FLIP_DURATION = 1.05f;

TileActor(TileLogic logic, BoardRenderer renderer) {
this.logic = logic;
flipped = logic.isFlipped();
flippedAnimation = AnimationState.IDLE;
column = logic.column;
row = logic.row;
}

void place() {
setPosition(calculateX(logic.column), calculateY(logic.row));
}

private float calculateX(int column) {
return column * (getWidth() + renderer.TILE_GAP) + renderer.boardXPosition;
}

private float calculateY(int row) {
return (renderer.manager.rows - row - 1) * (getHeight() + renderer.TILE_GAP) + renderer.boardYPosition;
}

@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(flipped ? front : back, calculateX(logic.column), calculateY(logic.row), getWidth(), getHeight());
}

@Override
public void act(float delta) {
super.act(delta);
if (flippedAnimation == AnimationState.IDLE && flipped != logic.isFlipped()) {
flippedAnimation = AnimationState.SCHEDULED;
}
if (flippedAnimation == AnimationState.SCHEDULED) {
playFlipAnimation();
}
if (flippedAnimation == AnimationState.COMPLETED) {
flippedAnimation = AnimationState.IDLE;
Gdx.app.log("TileActor.act", logic.value + (flippedAnimation.name()));
}
}

private void playFlipAnimation() {
flippedAnimation = AnimationState.PROGRESS;
Gdx.app.log("TileActor.playFlipAnimation", logic.value + (flippedAnimation.name()));
addAction(sequence(
parallel(// This does not happen, at least I can see no scale or fade animation
scaleTo(1, 0, FLIP_DURATION, Interpolation.pow5),
fadeOut(FLIP_DURATION, Interpolation.pow5)
),
new Action() {// This is executed as expected, I can see the log message
@Override
public boolean act(float delta) {
flipped = logic.isFlipped();
Gdx.app.log("TileActor.playFlipAnimation", logic.value + (flipped ? " " : " NOT ") + " flipped");
return true;
}
},
parallel(// This does not happen, at least I can see no scale or fade animation
scaleTo(1, 1, FLIP_DURATION, Interpolation.pow5),
fadeIn(FLIP_DURATION, Interpolation.pow5)
),
new Action() {// This is executed as expected, I can see the log message after the delay
@Override
public boolean act(float delta) {
flippedAnimation = AnimationState.COMPLETED;
Gdx.app.log("TileActor.playFlipAnimation", logic.value + (flippedAnimation.name()));
return true;
}
}
));
}
}

解决方案:

我的draw方法必须处理颜色变化并传递比例值,如下所示:

@Override
public void draw(Batch batch, float parentAlpha) {
final Color color = getColor();
batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
batch.draw(flipped ? front : back,
calculateX(logic.column), calculateY(logic.row),
getOriginX(), getOriginY(),
getWidth(), getHeight(),
getScaleX(), getScaleY(),
getRotation());
}

最佳答案

FadeActions 和 ColorActions 修改 Actor 的 Color 对象。绘图时必须将此颜色应用于批处理。

@Override
public void draw(Batch batch, float parentAlpha) {
Color color = getColor();
batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
batch.draw(flipped ? front : back, calculateX(logic.column), calculateY(logic.row), getWidth(), getHeight());
}

关于java - LibGDX Actor 不会绘制 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39028359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com