나는 안드로이드 프로그래밍에 익숙하지 않다. 내 코드에 도움이 필요하다. 볼 수있는 것처럼, onDraw 메서드와 onTouchEvent를 사용하여 만든 버튼을 클릭하면 메뉴가있다.안드로이드 게임 메뉴
public boolean onTouchEvent(MotionEvent event)
{
CoordCheck cc = new CoordCheck();
Log.d(TAG, "Coords: X=" + event.getX() + ",Y=" + event.getY()+"choice="+glb.getChoice());
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
float x, y;
x = event.getX();
y = event.getY();
//
// MAIN MENU
//
if(glb.getChoice()==0)
{
if (cc.ifMenu_exit(x, y))
{
thread.setRunning(false);
((Activity)getContext()).finish();
}
else if (cc.ifMenu_pagsasanay(x,y))
{
thread.menu_pagsasanay();
}
}
//
// PAGSASANAY MENU
//
if(glb.getChoice()==1)
{
Log.d(TAG,"PAGSASANAY MENU");
if (cc.ifPagsasanay_pitik(x, y))
{
pitik = new PitikBulagAnimation(
BitmapFactory.decodeResource(getResources(), R.drawable.hand_sprites)
, 450, 60 // initial position
, 350, 41 // width and height of sprite
, 50, 6); // FPS and number of frames in the animation
Log.d(TAG,"pitik");
thread.pitikAnimation();
}
else if (cc.ifPagsasanay_jnp(x, y))
{
jnp = new JNPAnimation(
BitmapFactory.decodeResource(getResources(), R.drawable.ai_sprite)
, 550, 70 // initial position
, 283, 41 // width and height of sprite
, 50, 4); // FPS and number of frames in the animation
Log.d(TAG,"jnp");
thread.jnpAnimation();
}
if(cc.ifBackButton(x, y))
{
thread.menu_main();
}
오류 ... glb.getChoice 값이 0이면보기에 기본 메뉴가 있음을 나타냅니다. 내 문제는, "pagsasanay"버튼을 (메인 메뉴 내부에서) 클릭하면 Pagsasanay 메뉴로 갈 수 있고 glb 클래스의 선택은 1로 설정되지만 거기에 도착하면 event.getX() 값은 다른 곳을 클릭 한 상태로 유지됩니다. 버튼 "pagsasanay"버튼과 정확히 같은 좌표입니다.