2D 그래픽 튜토리얼 (관심이있는 사람들, 그 중 하나는 @http://droidnova.com/)을 따라 갔고, 저는 상수를 경험했습니다. 내 onTouchEvent() 콜백에서 충돌이 발생합니다. 여전히 버그를 추적하려고하지만 문제를 디버깅하는 동안 onTouchEvent 콜백이 각 이벤트에 대해 두 번 호출되는 것을 발견했습니다. rerference를 들어Android 2.2 SurfaceView # 각 이벤트마다 onTouchEvent()가 두 번 호출됩니다.
내가 첫 번째 줄에 중단 점을 넣어 디버그 모드에서 실행
@Override
public boolean onTouchEvent(MotionEvent event)
{
int action = event.getAction();
synchronized (getHolder()) {
if (action == MotionEvent.ACTION_DOWN) {
if (gameObjects.size() < 2) {
currentlySelected = new GameObject(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
currentlySelected.getCoordinates().setX((int) event.getX());
currentlySelected.getCoordinates().setY((int) event.getY());
} else {
for (GameObject gameObject: gameObjects) {
if (gameObject.inBoundingBox(event.getX(), event.getY())) {
currentlySelected = gameObject;
break;
}
}
if (currentlySelected != null) {
// Remember to remove it from the list so that we don't waste time updating it in updatePhysics twice.
gameObjects.remove(currentlySelected);
}
}
} else if (action == MotionEvent.ACTION_UP && (currentlySelected != null)) {
gameObjects.add(currentlySelected);
currentlySelected = null;
} else if (action == MotionEvent.ACTION_MOVE) {
currentlySelected.getCoordinates().setX((int) event.getX());
currentlySelected.getCoordinates().setY((int) event.getY());
}
}
아니, 콜백은 다음과 액션의 호출됩니다 화면을 터치 할 때 ...
- 조치 = 0 (MotionEvent.ACTION_DOWN)
- 조치 = 0 (MotionEvent.ACTION_DOWN)
- 조치 = 1 (MotionEvent.ACTION_MOVE) 0,123,
- 조치 = 1 (MotionEvent.ACTION_MOVE)는
- 조치 = 2 (MotionEvent.ACTION_UP)
- 조치 = 2 (MotionEvent.ACTION_UP) 각각의 액션
는 두 번째의 동기화에서 나와서 요구. 누구든지이 행동의 이유를 알고 있습니까?
P.S. : 설명대로 추측했지만 더 많은 문제가 발생했습니다 ... 그게 나를위한 막 다른 길인 것 같아요. –
BUMP for interest –