AndEngine:旋转修改器在MultiTouch中无法用于第二根手指

时间:2013-02-18 13:00:11

标签: android andengine

我的游戏中有两个滑块,它们分别旋转和缩放+定位玩家精灵。

左滑块旋转精灵 和正确的比例+以一定的速度移动玩家

我已添加了MultiTouch扩展程序

问题在于;

当我首先触摸左滑块(先旋转)然后触摸第二个(即右滑块)时,一切都很完美。 但是,当我先触摸右侧滑块,然后触摸左侧时,会发生旋转,但是在视觉上看不到旋转。

可能是什么问题? 如果需要,请分享代码

ONAREATOUCHED的旋转滑动代码

    @Override
   public boolean onAreaTouched(TouchEvent touchEvent,float pTouchAreaLocalX,float pTouchAreaLocalY) {

        mPlayer.clearRotationModifiers();
        float currentRotationValue;

        if(touchEvent.isActionDown())
        {

            //gesture detector enabled for rotation slider only
            mGestureDetector.onTouchEvent(touchEvent.getMotionEvent());

            this.LastPositionTouched=touchEvent.getMotionEvent().getY();
            currentRotationValue=this.CalculateCurrentCalibratedValue(pTouchAreaLocalY);



            mPlayer.MakeRotation(currentRotationValue);
            mPlayer.pressedPlayerActionOnRotation=1; //press started
        }
        if( touchEvent.isActionMove() )
        {


            this.DistanceConveredSinceLastDownEvent=touchEvent.getMotionEvent().getY()-this.LastPositionTouched;

            if( Math.abs(this.DistanceConveredSinceLastDownEvent) > HUDBar.minScrollDistanceCovered ){

                    mPlayer.pressedPlayerActionOnRotation=1;
                    currentRotationValue=this.CalculateCurrentCalibratedValue(pTouchAreaLocalY);                                
                    mPlayer.MakeRotation(currentRotationValue);
                }
            this.LastPositionTouched=touchEvent.getMotionEvent().getY();

        }
        if(touchEvent.isActionUp())
        {
            this.LastPositionTouched=0;
            MainActivity.this.mPlayer.pressedPlayerActionOnRotation=0; //pressing stopped
            mPlayer.resetRotation(-90); 
            //----reset debug variables-----
        }
        return true;
    }
};

DepthSlider代码

    @Override
    public boolean onAreaTouched(TouchEvent touchEvent,float pTouchAreaLocalX,float pTouchAreaLocalY)
    {


        float ScaleValue,StringLengthFactor,SpeedFactor;

        //mPlayer.clearEntityModifiers();

        if(touchEvent.isActionDown())
        {

            //for implementing custom longpress
            this.isActionDownOccured=true;
            //mPlayer.pressedTime=touchEvent.getMotionEvent().getEventTime();
            this.initialTime=touchEvent.getMotionEvent().getDownTime();
            this.pressedTime=this.initialTime;

            /////////////////////////////////////////////       
            this.LastPositionTouched=touchEvent.getY();
            //gesturedetector onDown motionevent passed in onLongPress
        //  mGestureDetector.onTouchEvent(touchEvent.getMotionEvent());

            ScaleValue=this.CalculateCurrentCalibratedValue(pTouchAreaLocalY);                  
            StringLengthFactor =   ScaleValue * ScaleToStringLengthConversionFactor;
            SpeedFactor        =  (ScaleValue>0) ? ScaleValue * ScaleToSpeedConversionFactor:0;


            //---display local variables before set speed----------------
            /*MainActivity.this.txtLoggingSpriteVariables.setText( 
                    "TouchAreaLocalY: "+Float.toString(pTouchAreaLocalY)+
                    "  Speed From:"+
                    Float.toString(MainActivity.this.mPlayer.getSpeed())+
                    " to: "+ Integer.toString(currentSpeedValue) 
                    );
            */

            mPlayer.setSpeedAndScaleInParallel(SpeedFactor, ScaleValue);
            mPlayer.setDeltaStringLength(StringLengthFactor);

            MainActivity.this.txtDepthLogger.setText("DepthSlider Down Event"+(MainActivity.this.MoveEventDepthSliderCount++)+"\n"+
                     "PointerCount "+touchEvent.getMotionEvent().getPointerCount()+" New Scale:"  + mPlayer.getScaleX()+" \n " +
                     " New Speed: "+ mPlayer.getSpeed()
                    );

            MainActivity.this.mPlayer.pressedPlayerActionOnDepth=1; //depth slider pressed
        }
        if(touchEvent.isActionMove())
        {

            this.DistanceConveredSinceLastDownEvent=touchEvent.getY()-this.LastPositionTouched;

            if( Math.abs(this.DistanceConveredSinceLastDownEvent) > HUDBar.minScrollDistanceCovered ) {

                ScaleValue=this.CalculateCurrentCalibratedValue(pTouchAreaLocalY);                  
                StringLengthFactor =   ScaleValue * ScaleToStringLengthConversionFactor;
                SpeedFactor        =  (ScaleValue>0) ? ScaleValue * ScaleToSpeedConversionFactor:0;

                MainActivity.this.mPlayer.setSpeedAndScaleInParallel(SpeedFactor, ScaleValue);
                MainActivity.this.mPlayer.setDeltaStringLength(StringLengthFactor);

                //reset LongPress variables

                mPlayer.pressedPlayerActionOnDepth=1;
                this.initialTime=touchEvent.getMotionEvent().getEventTime();
                this.pressedTime=this.initialTime;

                MainActivity.this.txtDepthLogger.setText("DepthSlider Move Event"+(MainActivity.this.MoveEventDepthSliderCount++)+"\n"+
                        "PointerCount "+touchEvent.getMotionEvent().getPointerCount()+  " \n " +
                        "D: " + this.DistanceConveredSinceLastDownEvent +" New Scale:" + mPlayer.getScaleX()+" \n " +
                         " New Speed: "+ mPlayer.getSpeed()
                        );
                /*MainActivity.this.txtDepthLogger.setText("Depth CurrX"+touchEvent.getX()+"\n"+
                        "barxrange"+this.getWidth() +"DepthSlider Move Event"+(MainActivity.this.MoveEventDepthSliderCount++)+
                        "PointerID: "+touchEvent.getPointerID()
                        );*/ 



            }
            this.LastPositionTouched=touchEvent.getY();

        }
        if(touchEvent.isActionUp())
        {
            //-----reset speed,scale and stringlength will persist---------------
            MainActivity.this.mPlayer.pressedPlayerActionOnDepth=0; //pressing stopped
            this.isActionDownOccured=false;
            this.initialTime=0;
            this.pressedTime=0;
            this.LastPositionTouched=0;

            MainActivity.this.mPlayer.setSpeed(0);

            //----reset debug variables-----
            MainActivity.this.LongPressEventDepthSliderCount=0;
            MainActivity.this.MoveEventDepthSliderCount=0;

            //MainActivity.this.txtLoggingEventCount.setText("");
            //MainActivity.this.txtLoggingSpriteVariables.setText("");
        }
        return true;
    }
};

我正在使用GestureListener的onLongPress for Rotation Slider并为深度滑块编写自定义onLOngPress,因为手势监听器不支持MultiTouch。我在玩家精灵上执行onLongPress,OnScroll事件

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法

我正在清除touchevent上的所有先前的旋转修改器

我仅在有效事件上清除了旋转修改器。它开始工作。

也许对其他人也有用。