我使用此代码显示两个视图mRenderSurfaceView和gestureOverlayView:
relativeLayout = new RelativeLayout(this);
final FrameLayout.LayoutParams relativeLayoutLayoutParams = new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT , RelativeLayout.LayoutParams.FILL_PARENT );
gestureOverlayView = new GestureOverlayView(this);
gestureOverlayView.setEnabled(true);
this.mRenderSurfaceView = new RenderSurfaceView(this);
this.mRenderSurfaceView.setRenderer(mEngine);
surfaceViewLayoutParams = new RelativeLayout.LayoutParams(super.createSurfaceViewLayoutParams());
gestureOverlayView.addOnGesturePerformedListener(this);
relativeLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
relativeLayout.addView(gestureOverlayView, 1248,1152);
gestureOverlayView.setVisibility(View.GONE);
this.setContentView(relativeLayout, relativeLayoutLayoutParams);
我画了这个:
@Override
public boolean onTouch(View v, MotionEvent paramMotionEvent) {
//TODO Auto-generated method stub
if(paramMotionEvent.getAction() == MotionEvent.ACTION_DOWN) {
isDrawing = true;
}
//TouchEvent
if(paramMotionEvent.getAction() == MotionEvent.ACTION_UP) {
isDrawing = false;
rec = new Rectangle[250];
Arrays.fill( rec, null );
irec=0;
}
if (isDrawing = true) {
if (rec[249]!=null){
return false;
}
rec[irec] = new Rectangle(paramMotionEvent.getX(), paramMotionEvent.getY(), 1, 1);
if (irec != 0) {
Line l = new Line(rec[irec-1].getX(), rec[irec-1].getY(), rec[irec].getX(), rec[irec].getY());
l.setColor(0.5f, 1f, 0.3f);
mScene.attachChild(l);
}
irec++;
}
return true;
}
并在OnloadScene中我gestureOverlayView.setOnTouchListener(this);
我的场景做1248 * 1152,问题是公共布尔onTouch工作正常,如果我在向左,但如果在场景中向下移动或向右移动绘制。如何制作具有良好宽度和高度的视图(我猜这是问题,这保持相机比例)?
如果我使用mScene.setOnSceneTouchListener,绘制就可以,但手势不起作用......
答案 0 :(得分:0)
由velocityOnScreenControl.attachChild(l)解决; (private AnalogOnScreenControl velocityOnScreenControl;)使用AnalogOnScreenControl示例。