求助大神!!!Android中,为什么屏幕发生有touch事件却无法调用OnTouchEvent
以下是我的代码,我在OnTouchEvent中设置了打印语句,运行时没有出来,当点击屏幕时,直接是unfortunatelyXXXstoped,怎么回事啊?求助大神pub...
以下是我的代码,我在OnTouchEvent中设置了打印语句,运行时没有出来,当点击屏幕时,直接是unfortunately XXX stoped,怎么回事啊?求助大神
public class SFGame extends Activity{
private SFGameView gameView;
//private SFGameRenderer gameRenderer;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
gameView =new SFGameView(this);
setContentView(gameView);
}
@Override
protected void onResume(){
super.onResume();
gameView.onResume();
}
@Override
protected void onPause(){
super.onPause();
gameView.onPause();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
float x = event.getX();
float y = event.getY();
int height =SFEngine.display.getHeight()/4;
int playableArea = SFEngine.display.getHeight()-height;
System.out.println("aaaaaaaaaa");
if(y > playableArea){
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
if(x<SFEngine.display.getWidth()/2){
SFEngine.playerFlightAction =SFEngine.PLAYER_BANK_LEFT_1;
}else{
SFEngine.playerFlightAction =SFEngine.PLAYER_BANK_RIGHT_1;
}
break;
case MotionEvent.ACTION_UP:
SFEngine.playerFlightAction = SFEngine.PLAYER_RELEASE;
break;
}
}
return false;
}
} 展开
public class SFGame extends Activity{
private SFGameView gameView;
//private SFGameRenderer gameRenderer;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
gameView =new SFGameView(this);
setContentView(gameView);
}
@Override
protected void onResume(){
super.onResume();
gameView.onResume();
}
@Override
protected void onPause(){
super.onPause();
gameView.onPause();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
float x = event.getX();
float y = event.getY();
int height =SFEngine.display.getHeight()/4;
int playableArea = SFEngine.display.getHeight()-height;
System.out.println("aaaaaaaaaa");
if(y > playableArea){
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
if(x<SFEngine.display.getWidth()/2){
SFEngine.playerFlightAction =SFEngine.PLAYER_BANK_LEFT_1;
}else{
SFEngine.playerFlightAction =SFEngine.PLAYER_BANK_RIGHT_1;
}
break;
case MotionEvent.ACTION_UP:
SFEngine.playerFlightAction = SFEngine.PLAYER_RELEASE;
break;
}
}
return false;
}
} 展开
2013-07-20
展开全部
试试设置 setOnTouchListener
追问
可是我没有设置按钮响应,setOnTouchListener不是在有按钮的情况下使用么???我只是想触屏使用。该肿么办?大神,跪求!!!!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询