Surface GestureDetector出了点问题

时间:2015-03-06 19:04:43

标签: java android eclipse andengine

我不知道我做错了什么。但每当我调用这个特殊场景时,我的应用程序就会崩溃。关闭整个应用程序并让我回到我的模拟器的主屏幕。

public class Scientific_AbilityScene extends BaseScene{
private HUD scientific_abilityHUD;
private SurfaceGestureDetectorAdapter gDetector;
private Camera camera;
@Override
public void createScene() {

    createBackground();
    setupGestureDetection();
    onSurfaceGesture(null);

    this.setOnSceneTouchListener(gDetector);

}

private void setupGestureDetection(){

    gDetector = new SurfaceGestureDetectorAdapter(activity, 1f) {

         @Override
         protected boolean onSwipeUp() {
             onSurfaceGesture("Swipe\nUp");
                 return false;
         }

         @Override
         protected boolean onSwipeRight() {
             onSurfaceGesture("Swipe\nRight");
                 return false;
         }

         @Override
         protected boolean onSwipeLeft() {
                onSurfaceGesture("Swipe\nLeft");
                 return false;
         }

         @Override
         protected boolean onSwipeDown() {
             onSurfaceGesture("Swipe\nDown");
                 return false;
         }

         @Override
         protected boolean onSingleTap() {
             onSurfaceGesture("Tap");
                 return false;
         }

         @Override
         protected boolean onDoubleTap() {
             onSurfaceGesture("Double\nTap");
                 return false;
         }
    };
this.gDetector.setEnabled(true);
}

void onSurfaceGesture(CharSequence text) {
    final Text gestureText = new Text(0, 0, ResourcesManager.getInstance().font, text, new TextOptions(HorizontalAlign.CENTER), vbom);
    gestureText.setPosition((mWidth - gestureText.getWidth()) * 0.5f, (mHeight - gestureText.getHeight()) * 0.5f);
    gestureText.setScale(0.0f);
    gestureText.registerEntityModifier(new ScaleModifier(0.5f, 0.0f, 2f));
    this.attachChild(gestureText);

    }


@Override
public void onBackKeyPressed() {

    SceneManager.getInstance().loadReviewScene(engine);
    ResourcesManager.getInstance().button.play();
}

@Override
public SceneType getSceneType() {

    return SceneType.SCENE_SCIENTIFIC_ABILITY;
}

@Override
public void disposeScene() {

    camera.setHUD(null);
    camera.setCenter(240, 400);

}

private void createHUD()
{
    scientific_abilityHUD = new HUD();      
    camera.setHUD(scientific_abilityHUD);
}

private void createBackground()
{
    attachChild(new Sprite(240, 400, resourcesManager.bg, vbom)
    {
        @Override
        protected void preDraw(GLState pGLState, Camera pCamera) 
        {
            super.preDraw(pGLState, pCamera);
            pGLState.enableDither();
        }
    });
}

}

03-06 11:45:02.194: E/AndroidRuntime(6989): in writeCrashedAppName, pkgName :com.example.ncaereviewer
03-06 11:45:02.194: E/AndroidRuntime(6989):     at com.example.ncaereviewer.Scientific_AbilityScene$1.(Scientific_AbilityScene.java:41)
03-06 11:45:02.194: E/AndroidRuntime(6989):     at com.example.ncaereviewer.Scientific_AbilityScene.setupGestureDetection(Scientific_AbilityScene.java:41)
03-06 11:45:02.194: E/AndroidRuntime(6989):     at com.example.ncaereviewer.Scientific_AbilityScene.createScene(Scientific_AbilityScene.java:32)
03-06 11:45:02.194: E/AndroidRuntime(6989):     at com.example.ncaereviewer.BaseScene.(BaseScene.java:34)
03-06 11:45:02.194: E/AndroidRuntime(6989):     at com.example.ncaereviewer.Scientific_AbilityScene.(Scientific_AbilityScene.java:23)
03-06 11:45:02.194: E/AndroidRuntime(6989):     at com.example.ncaereviewer.SceneManager$9.onTimePassed(SceneManager.java:409)

所以错误提示我这个特定的行

gDetector = new SurfaceGestureDetectorAdapter(activity, 1f) {

感谢您的回答。

0 个答案:

没有答案