我正在製作一個java遊戲,當用戶按下某些鍵時,精靈會沿着這個方向移動,並且它會改變精靈以匹配用戶輸入的方向。 如果你想看到當前遊戲,頭到這個網站:http://thetutspace.org/acropolis/beta/使精靈移動,需要精靈停留在他最後一次移動的位置
這裏是我使用的代碼:
int x_posI = (int) x_pos;
int y_posI = (int) y_pos;
if (downPressed && leftPressed) {
g.drawImage(hero225, x_posI, y_posI, this);
spr270 = false;
} else if (downPressed && rightPressed) {
spr270 = false;
g.drawImage(hero135, x_posI, y_posI, this);
} else if (upPressed && rightPressed) {
spr270 = false;
g.drawImage(hero45, x_posI, y_posI, this);
} else if (upPressed && leftPressed) {
g.drawImage(hero315, x_posI, y_posI, this);
spr270 = false;
} else if (leftPressed == true) {
g.drawImage(hero270, x_posI, y_posI, this);
spr270 = true;
} else if (rightPressed == true) {
g.drawImage(hero90, x_posI, y_posI, this);
spr270 = false;
} else if (upPressed == true) {
g.drawImage(hero, x_posI, y_posI, this);
spr270 = false;
} else if (downPressed == true) {
g.drawImage(hero180, x_posI, y_posI, this);
spr270 = false;
}
else{
g.drawImage(hero, x_posI, y_posI, this);
}
if(spr270) {
g.drawImage(hero270, x_posI, y_posI, this);
}
當我按下左,這是發生了什麼: i.stack .imgur [點] com/owT3z.png
當我放手,這是我所發生的情況: i.stack.imgur.com/2Wrjr[dot]png
我怎樣才能使它所以角色保持朝左?
與您的問題無關,但與可讀性無關:爲什麼有'if(foo == true){'?爲什麼不'if(foo){'? – 2011-06-11 17:55:09
我沒有想到這一點,謝謝。 – Derek 2011-06-11 18:11:46
現在就你目前的問題,我只是對你的問題感到困惑。您可能需要描述原始文章中的一段或兩段描述您問題的詳細信息,以及在您嘗試解決問題時無法解決的問題。 – 2011-06-11 18:17:37