2013-02-18 18 views
1

我在游戏中有两个滑块,它们分别旋转和缩放播放器精灵的位置。AndEngine:旋转修饰符在MultiTouch中对于第二根手指不起作用

向左滑动旋转精灵 和右标+一些速度移动玩家

我已经包括了多点触控的扩展

的问题是;

当我先触摸左侧滑块(先旋转),然后再触摸右侧滑块时,一切正常。 但是,当我先触摸右侧滑块,然后再触摸左侧时,就会发生旋转,但旋转不会在视觉上看到。

可能是什么问题? 如果需要生病份额代码

旋转滑块CODE FOR 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代码使用GestureListener的onLongPress的旋转滑块

@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; 
    } 
}; 

IM和写定制onLOngPress深度滑块,因为手势监听器不支持MultiTouch。林表演onLongPress,对玩家精灵OnScroll事件

+0

很难知道发生了什么事,却没有看你的代码,但你看过这个讨论吗? http://www.andengine.org/forums/tutorials/problem-with-two-analog-sticks-t9567.html – 2013-02-19 00:01:51

+0

是的,我读了那个链接。它与我的问题不同,即时设置场景中的HUD。不是现场的孩子。 – 2013-02-19 04:45:06

+0

我已添加代码,请现在看看 – 2013-02-20 09:21:00

回答

0

我发现这个解决我的问题

我正在收拾上的TouchEvent所有以前的旋转调节剂

我清理只对有效旋转调节剂events.And它开始工作。

也许它对其他人也有用。