1

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

左滑块旋转精灵和右缩放 + 以一定速度移动玩家

我已经包含了 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;
    }
};

深度滑块代码

    @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 用于 Rotation Slider,并为深度滑块编写了自定义 onLongPress,因为手势侦听器不支持 MultiTouch。我在播放器精灵上执行 onLongPress、OnScroll 事件

4

1 回答 1

0

我找到了解决我的问题的方法

我在 touchevent 上清除了所有以前的旋转修改器

我只在有效事件上清除了旋转修饰符。它开始工作了。

也许它对其他人也有用。

于 2013-03-15T06:44:00.677 回答