我的角色是一个演员,当我将它向左或向右移动时,我给了他一个 moveTo 动作,依此类推。
和确实工作正常LEFT
。UP
我可以看到,因为我的调试模式向我显示了 MapArray 中字符的当前位置。(绘制矩形的颜色)
如果我打电话给它DOWN
,RIGHT
它确实会走路UP
,或者LEFT
但我确信我的方向是正确的。如果我点击右,他会走上去,如果我点击下,他也会走上去!
我希望你能告诉我为什么他们走错了方向!
这是我将动作设置为演员的移动方法:
private void move(Status direction) {
switch (direction) {
case LEFT:
this.clearActions();
this.addAction(Actions.sequence(
Actions.moveTo((getX() - Config.BLOCK_SIZE), getY(), speed),
new RunnableAction() { //to know when hes done to get the next move
public void run() {
moveDone = true;
}
}));
break;
case RIGHT:
this.clearActions();
this.addAction(Actions.sequence(
Actions.moveTo((getX() + Config.BLOCK_SIZE), getY(), speed),
new RunnableAction() {
public void run() {
moveDone = true;
}
}));
case DOWN:
this.clearActions();
this.addAction(Actions.sequence(
Actions.moveTo(getX(), (getY() - Config.BLOCK_SIZE), speed),
new RunnableAction() {
public void run() {
moveDone = true;
}
}));
case UP:
this.clearActions();
this.addAction(Actions.sequence(
Actions.moveTo(getX(), (getY() + Config.BLOCK_SIZE), speed),
new RunnableAction() {
public void run() {
moveDone = true;
}
}));
default:
break;
}
}
这就是我所说的。我希望我发布更多“长”代码可以!它或多或少只是设置正确的位置。
@Override
public void act(float delta) {
super.act(delta);
if (moveDone) {
if (screen.pad.isTouched()) {
// check in which direction is the touchcontroller
if (screen.pad.getKnobPercentX() < 0
&& Math.abs(screen.pad.getKnobPercentY()) < Math
.abs(screen.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 (screen.pad.getKnobPercentX() > 0
&& Math.abs(screen.pad.getKnobPercentY()) < Math
.abs(screen.pad.getKnobPercentX())) {
if (checkNextMove(Status.RIGHT)) {
move(Status.RIGHT);
this.status = Status.RIGHT;
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 (screen.pad.getKnobPercentY() > 0) {
if (checkNextMove(Status.DOWN)) {
this.status = Status.DOWN;
move(Status.DOWN);
this.screen.map.mapArray[(int) (this.mapPos.x)][(int) this.mapPos.y] = Config.EMPTYPOSITION;
this.screen.map.mapArray[(int) (this.mapPos.x)][(int) this.mapPos.y + 1] = Config.CHARSTATE;
this.mapPos.y++;
moveDone = false;
}
} else {
if (checkNextMove(Status.UP)) {
this.status = Status.UP;
move(Status.UP);
this.screen.map.mapArray[(int) (this.mapPos.x)][(int) this.mapPos.y] = Config.EMPTYPOSITION;
this.screen.map.mapArray[(int) (this.mapPos.x)][(int) this.mapPos.y - 1] = Config.CHARSTATE;
this.mapPos.y--;
moveDone = false;
}
}
} else {
setIdle();
}
}
// methode from the absctract to change sprites
updateSprite(delta);
}
这是一张图片,如果我走对了,它的样子。他站在绿地的左边,现在在右边的地里。但图片不存在。
这里是char的绘制:
@Override
public void draw(SpriteBatch batch, float parentAlpha) {
sprite.setPosition(this.getX(), this.getY());
sprite.draw(batch);
}
我真的不明白错误在哪里。希望你能帮忙!