퍼즐 게임을 하나 만들고 있습니다..
터치 이벤트시 지정한 메소드가 무조건 두번 실행이 됩니다..ㅠㅠ
도저히 원인을 알 수 없어 도움을 청해봅니다..
-----> 터치 이벤트 부분
case MotionEvent.ACTION_UP:
touchItem(x, y);
-----> 터치시 실행되는 메소드
public void touchItem(int x, int y) {
if (item.get("uncle").isSelected(x, y)) {
stage.useItemUncle();
} else if (item.get("mother").isSelected(x, y)) {
stage.useItemMother();
} else if (item.get("father").isSelected(x, y)) {
stage.useItemFather();
}
}
---> stage class에서 실행되는 메소드
public void useItemMother() {
isItemDestroy = true;
int blockNum = selectBlock.getBlockNum();
destroyBlocks = getTargetBlock(blockNum);
destroyBlocks.add(selectBlock);
destroyBlocks();
}
이런 식인데..
핵심 소스만 올려봅니다.
저게 다인데.. 왜 무조건 두번 실행이 될까요..
터치이벤트 전체소스입니다.
=============================
@Override
public boolean onTouchEvent(MotionEvent event) {
int x = (int) (event.getX() * Screen.getTouchScaleX());
int y = (int) (event.getY() * Screen.getTouchScaleY());
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = x;
startY = y;
case MotionEvent.ACTION_UP:
endX = x;
endY = y;
if (gameState == GAME_STATE_PLAYING) {
controlBlocks();
} else if (gameState == GAME_STATE_FAIL) {
handler.sendMessage(Message.obtain(handler, GAME_STATE_FAIL));
touchMissionFail(x, y);
} else if (gameState == GAME_STATE_SUCCESS) {
handler.sendMessage(Message.obtain(handler, GAME_STATE_SUCCESS));
touchMissionSuccess(x, y);
} else if (gameState == GAME_STATE_CLOSE) {
handler.sendMessage(Message.obtain(handler, GAME_STATE_CLOSE));
touchPlayExit(x, y);
}
touchItem(x, y);
}
return true;
}