嗨,我正在制作一个小游戏并且遇到了这个问题,当我进行正常或慢速移动时事件运行良好但是当我进行非常快速的移动时,事件崩溃了。请问我该怎么办? 这是我的Sprite的onAreaTouch事件:
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
int posInicial=estadoCarta;
switch(pSceneTouchEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
posX=getX()-getWidth()/2;
posY=getY()-getHeight()/2;
this.setScale(1.2f);
break;
case MotionEvent.ACTION_MOVE:
switch(estadoCarta){
case POS_PJ1:
this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
if(pSceneTouchEvent.getY()<=430){
this.setAlpha((float) 0.5);
estadoCarta=POS_SELECIONADO_MESA;
}
break;
case POS_SELECIONADO_MESA:
this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
if(pSceneTouchEvent.getY()>430){
this.setAlpha((float) 1);
estadoCarta=POS_PJ1;
}
break;
}
break;
case MotionEvent.ACTION_UP:
this.setScale(1.0f);
switch(estadoCarta){
case POS_PJ1:
setPosition(posX+getWidth()/2,posY+getHeight()/2);
estadoCarta=posInicial;
break;
case POS_SELECIONADO_MESA:
Posicion pos=escena.getPosicionLibre();
this.setPosition(pos.x, pos.y);
escena.Juega(this);
break;
}
break;
default:
this.setScale(1.0f);
switch(estadoCarta){
case POS_PJ1:
setPosition(posX+getWidth()/2,posY+getHeight()/2);
estadoCarta=posInicial;
break;
case POS_SELECIONADO_MESA:
Posicion pos=escena.getPosicionLibre();
this.setPosition(pos.x, pos.y);
escena.Juega(this);
break;
case POS_MESA:
this.setAlpha(0.5f);
estadoCarta=POS_PARA_JUGAR;
break;
case POS_PARA_JUGAR:
this.setAlpha(1f);
estadoCarta=POS_MESA;
break;
}
break;
}
return true;
}
我重复这个问题只是在我快速行动的时候。
答案 0 :(得分:0)
解决了!!! 我在主要游戏活动的EngineOptions onCreateEngineOptions()中使用此代码:
public EngineOptions onCreateEngineOptions()
{
camera = new BoundCamera(0, 0, 800, 480);
EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), this.camera);
engineOptions.getAudioOptions().setNeedsMusic(true).setNeedsSound(true);
engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
engineOptions.getTouchOptions().setTouchEventIntervalMilliseconds(1);
return engineOptions;
}
这有助于我将正常的20毫秒转换为1.然后触摸效果响应更快!!