0
我是新來android編程。我需要幫助我的code.As你可以看到,我有一個菜單,點擊我使用onDraw方法和onTouchEvent的按鈕後。Android遊戲菜單
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();
}
err .. glb.getChoice如果值爲零,則表示該視圖包含主菜單。我的問題是,如果我點擊「pagsasanay」按鈕(主菜單內),我可以去Pagsasanay菜單,並在glb類中的選擇將被設置爲1,但到達那裏後,event.getX()值仍然因此點擊另一個按鈕與「pagsasanay」按鈕的座標完全相同