Manager.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. var Dir_Up = 1;
  2. var Dir_Down = 2;
  3. var Dir_Left = 4;
  4. var Dir_Right = 8;
  5. var Dir_Left_Up = 5;
  6. var Dir_Right_Up = 9;
  7. var Dir_Left_Down = 6;
  8. var Dir_Right_Down = 10;
  9. cc.Class({
  10. extends: cc.BaseClass,
  11. properties: {
  12. },
  13. ctor: function () {
  14. this.m_Dir = 0; //方向
  15. this.m_TouchStartX = 0; //起始点
  16. this.m_TouchStartY = 0; //起始点
  17. this.m_TouchTurnX = 0; //拐点
  18. this.m_TouchTurnY = 0; //拐点
  19. this.m_ActMarkArr = new Array(4, 10, 5 ,6);//← ↘ ↖ ↙ , 9 ↗
  20. this.m_MarkIndex = null;
  21. this.m_CurAct = null;
  22. this.m_ActTime = 0;
  23. this.m_ShowLogArr = new Array();
  24. this.m_ShowLogArr[1] = '↑'
  25. this.m_ShowLogArr[2] = '↓'
  26. this.m_ShowLogArr[4] = '←'
  27. this.m_ShowLogArr[8] = '→'
  28. this.m_ShowLogArr[5] = '↖'
  29. this.m_ShowLogArr[9] = '↗'
  30. this.m_ShowLogArr[6] = '↙'
  31. this.m_ShowLogArr[10] = '↘'
  32. },
  33. onLoad : function() {
  34. this.m_BtTouch = this.$('Touch');
  35. this.m_NdView = this.$('View');
  36. this.m_spTip = this.$('Touch@Sprite');
  37. //按钮监听
  38. this.m_BtTouch.on(cc.Node.EventType.TOUCH_START,this.onTouchBegan.bind(this), this.m_BtTouch);
  39. this.m_BtTouch.on(cc.Node.EventType.TOUCH_MOVE,this.onTouchMoved.bind(this),this.m_BtTouch);
  40. this.m_BtTouch.on(cc.Node.EventType.TOUCH_END, this.onTouchOver.bind(this), this.m_BtTouch);
  41. this.m_BtTouch.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchOver.bind(this), this.m_BtTouch);
  42. this.m_spTip.enabled = false;
  43. },
  44. //触摸事件
  45. onTouchBegan :function(event){
  46. event.stopPropagation();
  47. //滑动起始点
  48. this.m_TouchStartX = event.touch.getLocation().x;
  49. this.m_TouchStartY = event.touch.getLocation().y;
  50. this.m_TouchTurnX = event.touch.getLocation().x;
  51. this.m_TouchTurnY = event.touch.getLocation().y;
  52. this.m_spTip.enabled = true;
  53. this.m_MarkIndex = 0;
  54. this.m_ActTime = 0;
  55. this.m_CurAct = null;
  56. this.m_NdView.setPosition(-2000,0);
  57. return true;
  58. },
  59. onTouchMoved :function(event){
  60. if(this.m_MarkIndex == null) return
  61. //屏幕坐标转节点坐标
  62. var Now = new Date().getTime();
  63. var MoveX = this.m_TouchTurnX - event.touch.getLocation().x;
  64. var MoveY = this.m_TouchTurnY - event.touch.getLocation().y;
  65. //轨迹判断
  66. if(this.m_ActTime != 0 && Now - this.m_ActTime > 100){
  67. this.m_TouchTurnX = event.touch.getLocation().x;
  68. this.m_TouchTurnY = event.touch.getLocation().y;
  69. var Mark = 0;
  70. if(Math.abs(MoveX) > 20) Mark += (MoveX>0?Dir_Left:Dir_Right);
  71. if(Math.abs(MoveY) > 20) Mark += (MoveY>0?Dir_Down:Dir_Up);
  72. if(this.m_CurAct == null) this.m_CurAct = Mark;
  73. //console.log('###',this.m_MarkIndex, this.m_ShowLogArr[Mark], Mark, Math.abs(MoveX),Math.abs(MoveY) )
  74. //拐点
  75. if(this.m_CurAct != Mark && this.m_ActMarkArr.length > this.m_MarkIndex) {
  76. if(this.m_CurAct != this.m_ActMarkArr[this.m_MarkIndex]){ //失败
  77. //console.log('onTouchMoved ',this.m_CurAct, this.m_ActMarkArr[this.m_MarkIndex], this.m_MarkIndex )
  78. this.m_MarkIndex = null;
  79. this.m_spTip.enabled = false;
  80. return
  81. }else{
  82. this.m_MarkIndex++;
  83. this.m_CurAct = Mark;
  84. }
  85. }
  86. }
  87. this.m_ActTime = Now;
  88. },
  89. onTouchOver :function(event) {
  90. if(this.m_MarkIndex == null) return
  91. var MoveX = this.m_TouchTurnX - event.touch.getLocation().x;
  92. var MoveY = this.m_TouchTurnY - event.touch.getLocation().y;
  93. var MoveX2 = this.m_TouchStartX - event.touch.getLocation().x;
  94. var MoveY2 = this.m_TouchStartY - event.touch.getLocation().y;
  95. var Mark = 0;
  96. if(Math.abs(MoveX) > 20) Mark += (MoveX>0?Dir_Left:Dir_Right);
  97. if(Math.abs(MoveY) > 20) Mark += (MoveY>0?Dir_Down:Dir_Up);
  98. if(this.m_CurAct == null) this.m_CurAct = Mark;
  99. //console.log('###',this.m_MarkIndex, this.m_ShowLogArr[Mark], Mark, Math.abs(MoveX),Math.abs(MoveY) )
  100. //console.log('###2 ',Math.abs(MoveX2) , Math.abs(MoveY2) )
  101. //拐点
  102. if(this.m_ActMarkArr.length > this.m_MarkIndex && Math.abs(MoveX2) < 50 && Math.abs(MoveY2) < 50) {
  103. if(this.m_CurAct == this.m_ActMarkArr[this.m_MarkIndex]) this.m_MarkIndex++;
  104. }
  105. if(this.m_ActMarkArr.length <= this.m_MarkIndex) this.m_NdView.setPosition(0,0);
  106. this.m_MarkIndex = null;
  107. this.m_spTip.enabled = false;
  108. },
  109. OnClick_BtWaring:function(Data, bWaring) {
  110. var QueryW = new CMD_GP_C_Warning();
  111. QueryW.bWarning = parseInt(bWaring);
  112. var LoginMission = new CGPLoginMission(this, MDM_GP_MANAGER, SUB_GP_WARNING, QueryW);
  113. },
  114. OnClick_BtDestroy:function() {
  115. this.ShowAlert('確認?', Alert_All, function(Res){
  116. if(Res){
  117. var LoginMission = new CGPLoginMission(this, MDM_GP_MANAGER, SUB_GP_DESTROY, {}, 0);
  118. }
  119. }.bind(this));
  120. },
  121. OnMsgRes:function(Msg){
  122. this.ShowAlert(Msg);
  123. },
  124. // update (dt) {},
  125. });