[更新]我稍微改变了顺序,所以我在方法末尾调用了super.act(delta)
,它似乎有点帮助!但还不太确定。
我的 map 有一个方形系统。所以它是一个二维数组,我移动一步,图形确实从一个方格移动到下一个方格。虽然不可能“停止”两个方 block 之间的数字。
当我的角色进行一个 Action 时,我检查触摸板是否被触摸,如果是,我开始下一步 Action 。虽然有时它似乎会滞后,但我不知道为什么!?我真的希望你能找到“滞后”。以下是我如何计算我的 Actor
角色的 act()
内的下一步 Action :
@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
好的,我确信您需要更多信息。像这样检查 Action :
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 操作。
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。
我真的希望你能帮忙。如果您需要更多信息,请通过评论告诉我!
最佳答案
有比 StackOverflow 更好的工具来优化 Android 代码。使用分析器并查看实际发生的情况。具体来说,traceview 分析器:how to use traceview in eclipse for android development? (如果您不使用Eclipse,则可以直接通过ADT使用traceview。)
关于java - 开始下一个 moveTo 操作时出现小滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16212825/