我正在尝试使用 Action FadeOut 淡出 Actor。但是,我发现 no action 对我的对象根本不起作用。我的类的层次结构是这样的:
Actor -> MoveableObject -> Knight
Stage -> KnightGroup (Group) -> Knight
我的骑士 Actor 的 Action 根本不起作用。但是,我的 KnightGroup 组的操作有效。这是我的骑士的代码:
public class Knight extends Players {
public Knight() {
setWidth(96);
setHeight(96);
setPosition(100, 90);
//Doesn't work
AlphaAction action = new AlphaAction();
action.setAlpha(0f);
action.setDuration(1f);
addAction(action);
//Doesn't work
addAction(fadeOut(1f));
addAction(Actions.scaleBy(1f, 1f));
}
@Override
public void act(float delta){
super.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.setColor(getColor().r, getColor().g, getColor().b, getColor().a);
batch.draw(animation[currentState], getX(), getY(), getWidth(), getHeight());
}
}
我一生都无法弄清楚问题是什么。在
MoveableObject
中的操作(骑士的 parent )也不起作用。我最好的猜测是将 Actor 包裹在 Group
中将 render
actions
那些 Actor 无效。 KnightGroup
是我的代码中非常重要的一部分,我必须进行大量重构才能将其删除。其他人可以对这个问题有所了解吗?
最佳答案
在 Actor
对方法进行分类 act(float delta)
电话act(delta)
所有注册 Action
s本Actor
.所以你必须确保你调用 super.act(delta)
在 Actor
的每个子类中,使 act(delta)
Actor
中的方法被调用。
关于LibGDX 场景 2D : Actions won't work at all for actors inside groups,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22033512/