【发布时间】:2015-02-15 20:08:14
【问题描述】:
我的游戏有一个更新方法来处理我的角色的火能力。 我的问题是我的游戏逻辑,子弹应该从我的角色位置发射,在游戏开始时(不移动角色)发射子弹来自角色的位置,但是当我移动我的角色时,子弹的开始位置和人物的位置不一样。
子弹的方向取决于玩家的方向。
private void update() {
Vector2 direction = new Vector2(0, 0);
if (Gdx.input.isKeyPressed(Keys.D)) {
direction.x = 1f ;
}
if (Gdx.input.isKeyPressed(Keys.A)) {
direction.x = -1f ;
}
if (Gdx.input.isKeyPressed(Keys.W)) {
direction.y = 1f ;
}
if (Gdx.input.isKeyPressed(Keys.S)) {
direction.y = -1f;
}
if (direction.x != 0 || direction.y != 0) {
playerDirection.set(direction);
System.out.println("player x: " +playerDirection.x + "\t" +"player y:"+playerDirection.y);
}
if (Gdx.input.isKeyPressed(Keys.F)) {
bulletPos = new Vector2(startPos);
bulletDirection.set(playerDirection);
}
if (bulletPos != null) {
bulletPos.x += direction.x;
bulletPos.y +=direction.y;
if (bulletPos.x < 0 || bulletPos.x > mapPixelWidth
|| bulletPos.y < 0 || bulletPos.y > mapPixelHeight) {
bulletPos = null;
}
}
}
谁能知道逻辑错误,或者那里的任何人都可以提供向一个方向射击的简单逻辑?
【问题讨论】:
标签: libgdx