0

我使用此代码显示两个视图 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 绘制没问题,但手势不起作用......

4

1 回答 1

0

Solved by velocityOnScreenControl.attachChild(l); of (private AnalogOnScreenControl velocityOnScreenControl;) Use AnalogOnScreenControl example.

于 2013-03-18T22:03:36.737 回答