我尝试在andengine中绘制手势 我创造了这个:
protected int getLayoutID() {
return R.layout.gesture;
}
protected int getRenderSurfaceViewID() {
return R.id.gesture_rendersurfaceview;
}
protected int getGestureOverlayViewID() {
return R.id.gesture_GestureOverlayView;
}
在Gesture.xml中我:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<org.anddev.andengine.opengl.view.RenderSurfaceView
android:id="@+id/gesture_rendersurfaceview"
android:layout_width="240px"
android:layout_height="240px"
android:layout_margin="10px" />
<org.anddev.andengine.opengl.view.GestureOverlayView
android:id="@+id/gesture_GestureOverlayView"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0" />
</AbsoluteLayout>
我使用它,通常是标准代码
mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mLibrary.load()) {
finish();
}
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gesture_GestureOverlayView);
gestures.addOnGesturePerformedListener(this);
但程序崩溃了GestureOverlayView手势=(GestureOverlayView)findViewById(R.id.gesture_GestureOverlayView);,请问AndEngine如何适应?
答案 0 :(得分:1)
在and-engine中已经有一个手势检测器类
org.andengine.input.touch.detector.SurfaceGestureDetectorAdapter
您可以使用它进行滑动检测并且您的要求不明确但可能会对您有帮助。
protected void onCreate(Bundle pSavedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(pSavedInstanceState);
this.mSGDA = new SurfaceGestureDetectorAdapter(this) {
@Override
protected boolean onSingleTap() {
// onSurfaceGesture("Tap");
return false;
}
@Override
protected boolean onSwipeDown() {
onSurfaceGesture("Swipe Down");
return false;
}
@Override
protected boolean onSwipeLeft() {
onSurfaceGesture("Swipe Left");
return false;
}
@Override
protected boolean onSwipeRight() {
onSurfaceGesture("Swipe Right");
return false;
}
@Override
protected boolean onSwipeUp() {
onSurfaceGesture("Swipe Up");
return false;
}
@Override
protected boolean onDoubleTap() {
// onSurfaceGesture("Double Tap");
return false;
}
};
this.mSGDA.setEnabled(true);
}
并注册
this.mScene.setOnSceneTouchListener(this.mSGDA);
答案 1 :(得分:0)
鉴于您提供的信息非常有限,您的GestureOverlayView
构造函数可能会被破坏。