0
내 배가 방향키를 눌러 x 및 y 경계로 이동할 때 직교 타일 맵 자바 게임을하고 있습니다 (의도 한대로) 이동을 멈 춥니 다.하지만 키를 계속 누르고 있으면 화면에서 나옵니다. 여기 자바 게임 - 키 누름
나는 코드를 사용하고 있습니다 :@Override
public boolean keyDown(int keycode) {
ship = world.getShip();
switch(keycode){
case Keys.W:
if (ship.getPosition().y<28.5f){
ship.getVelocity().y = 1;}
else {
ship.getVelocity().y = 0;
}
break;
case Keys.S:
if (ship.getPosition().y1){
ship.getVelocity().y = -1;}
else {
ship.getVelocity().y = 0;
}
break;
case Keys.A:
if (ship.getPosition().x0)
ship.getVelocity().x = -1.5f;
else{
ship.getVelocity().x = 0;
}
break;
case Keys.D:
if (ship.getPosition().x<39){
ship.getVelocity().x = 1;
}
else{
ship.getVelocity().x = 0;
}
break;
default:
break;
}
return true;
}
@Override
public boolean keyUp(int keycode) {
ship = world.getShip();
switch(keycode){
case Keys.W:
if(ship.getVelocity().y == 1)
ship.getVelocity().y = 0;
break;
case Keys.S:
if(ship.getVelocity().y == -1)
ship.getVelocity().y = 0;
break;
case Keys.A:
if(ship.getVelocity().x == -1.5f)
ship.getVelocity().x = 0;
break;
case Keys.D:
if(ship.getVelocity().x == 1)
ship.getVelocity().x = 0;
break;
default:
break;
}
return true;
}
내가 뭘 키를 누르면 유지하고있는 경우 화면에 내 배를 유지해야합니까?
코드, 입력/출력 및 HTML이나 XML과 같은 구조화 된 문서에 코드 형식을 사용하십시오. 이를 위해 샘플을 선택하고 메시지/편집 양식 위에있는 '{}'버튼을 클릭하십시오. –