누군가가 나를 깨달을 수 있습니까?화면에서 물체를 움직이는 데 문제가 발생했습니다.
나는 공을 자동으로 만들어서 한 모서리에서 다른 모서리로 이동해야하는 게임을하고 있습니다.
나는 공을 만들고 오른쪽 아래 모서리에서 왼쪽 위 모퉁이로 움직일 수 있었지만, 왼쪽 모서리에서 오른쪽 상단 모서리로하는 방법을 알아낼 수 없었다.
첨부 된 코드 중 일부는 내 논리의 그래프입니다.
case 1: // From one side to the other, in two axes
switch (subScenario) {
case 0: // Bottom right corner to top left corner.
posX = panelWidth;
posY = panelHeight;
directionX = (rnd.nextInt(2) + 1)*-1;
directionY = directionX;
case 1: // Top left corner to bottom right
posX = 0;
posY = 0;
directionX = (rnd.nextInt(2) + 1)*1;
directionY = directionX;
case 2: // Bottom left corner to top right corner
posX = 0;
posY = panelHeight;
directionX = directionY;
directionY = (rnd.nextInt(2) + 1)*-1;
}
break;
}
그렇다면 오류는 어디에서 발생합니까? –
케이스 2에서 directionX와 directionY 라인을 전환 해보십시오. – 17slim
마지막 코멘트를 잊어 버리 셨습니다. 잠시 생각하지 못했습니다. 'directionX = (rnd.nextInt (2) + 1) * 1'을 설정하고'directionY'을 그대로 두십시오. – 17slim