문제는 Android 경로 모양과 관련됩니다. 그것은 화면 Canvas의 객체를 가리키는 화살표로 사용하는 삼각형입니다. 이것은 2d 게임을위한 것입니다. 화면 중앙에있는 플레이어, 그 주변의 물체 및 오프 스크린.캔버스 및 경로를 사용하여 한 지점을 2 차원 회전합니다.
이 화살표는 화면 중심을 중심으로 회전하며 플레이어 주변의 원을 그리며 회전합니다. 화살표는 플레이어가 앞으로 이동해야하는 대상을 가리 킵니다.
내가 지금하고있는 것은 다소 효과가 있지만, 화살표는 어리석은 속도로 원 주위를 돌아 다니고 있습니다. 재미있게도, 그들은 올바른 방향을 가리키고 있지만, 원의 오른쪽 지점에 머무르지는 않습니다. (화살표가 북동쪽을 가리키고 있으면 화살표가 원의 북동쪽 부분에 있어야 함)
나는 그것이 수학 때문일 것이라고 확신합니다. 아마 atan2 잘못 사용하고 있습니다. 아니면 canvas.translate wrong. 또는 atan2를 전혀 사용하지 않아야합니다. 도움! :) 여기
코드입니다 :// set the shape of our radar blips
oBlipPath.moveTo(0, -5);
oBlipPath.lineTo(5, 0);
oBlipPath.lineTo(0, 5);
// Paint all the enemies and radar blips!
for(int i=0; i<iNumEnemies; i++){
if (oEnemies[i].draw(canvas, (int)worldX, (int)worldY)){
//calculate the degree the object is from the center of the screen.
//(user is the player. this could be done easier using iWidth and iHeight probably)
//we use a world coordinate system. worldY and worldX are subtracted
fDegrees = (float)Math.toDegrees(Math.atan2((oEnemies[i].getEnemyCenterY()-worldY)-user.getShipCenterY(), (oEnemies[i].getEnemyCenterX()-worldX)-user.getShipCenterX()));
canvas.save();
//get to the center
canvas.translate((iWidth/2) , (iHeight/2));
//move a little bit depending on direction (trying to make arrows appear around a circle)
canvas.translate((float)(20 * Math.cos(fDegrees)), (float)(20* Math.sin(fDegrees)));
//rotate canvas so arrows will rotate and point in the right direction
canvas.rotate(fDegrees);
//draw arrows
canvas.drawPath(oBlipPath, oBlipPaint);
canvas.restore();
}
}
+1 나는 안드로이드 녀석이 아니지만,이게 더 나아 보인다. 명령문 명령이 다른 방법을 제시 할지라도, 회전이 _ 번역 전에 _ 생기는 것으로 나타납니다. – trashgod