【发布时间】:2023-03-29 13:55:02
【问题描述】:
[更新] 我稍微改变了顺序,所以我在方法结束时调用了super.act(delta),这似乎有点帮助!但还不确定。
我的地图有一个正方形系统。所以它是一个二维数组,我做了一个动作,这个数字确实从一个正方形移动到下一个正方形。虽然不可能“停止”两个方格之间的数字。
当我的角色移动时,我检查触摸板是否被触摸,如果是,我开始下一步移动。虽然它有时似乎滞后,我不知道为什么!?我真的希望你能找到“滞后”。以下是我如何计算我的Actor 字符的act() 内的下一步动作:
@Override
public void act(float delta) {
super.act(delta); // so the actions work
if (moveDone) {
if (screen.gameHud.pad.isTouched()) {
// check in which direction is the touchcontroller
if (screen.gameHud.pad.getKnobPercentX() < 0
&& Math.abs(screen.gameHud.pad.getKnobPercentY()) < Math
.abs(screen.gameHud.pad.getKnobPercentX())) {
// checkt if the |x|>|y|
if (checkNextMove(Status.LEFT)) {
this.status = Status.LEFT;
move(Status.LEFT);
this.screen.map.mapArray[(int) (this.mapPos.x)][(int) this.mapPos.y] = Config.EMPTYPOSITION;
this.screen.map.mapArray[(int) (this.mapPos.x - 1)][(int) this.mapPos.y] = Config.CHARSTATE;
this.mapPos.x--;
moveDone = false;
}
} else if //.... rest is the same just with other directions
else{ //if touchpad isnt touched!
setIdle();
}
updateSprite(delta); //just change the textureRegion if its time for that
} //methode end
好的,我相信您需要更多信息。像这样的检查动作:
case LEFT:
if (this.mapPos.x - 1 >= 0)
if (this.screen.map.mapArray[(int) (this.mapPos.x - 1)][(int) this.mapPos.y] == Config.EMPTYPOSITION)
return true;
break; //same for all other just direction changin
我猜你需要知道的最后一个是move(_)。它确实为我的人物添加了一个 moveTo Action。
public void move(Status direction) {
switch (direction) {
case LEFT:
this.addAction(Actions.sequence(
Actions.moveTo((getX() - Config.BLOCK_SIZE), getY(), speed),
moveDoneAction));
break;
moveDoneAction 是一个简单的RunnableAction,如果移动完成,它会将boolean moveDone 设置为true。
我真的希望你能帮忙。如果您需要更多信息,请在评论中告诉我!
【问题讨论】:
标签: java android animation libgdx