ui_wei_chi_pointer.ts 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { _decorator, Component, Label, Node, Tween, UITransform, Vec3 } from 'cc';
  2. import { ui_base } from './ui_base';
  3. import { wei_chi_pointer_data } from '../../../data/data';
  4. import { tools } from '../../tools';
  5. import { gameManager } from '../gameManager';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('ui_wei_chi_pointer')
  8. export class ui_wei_chi_pointer extends ui_base {
  9. @property(Node) img_hand:Node = null; //无效果一张图
  10. @property(Node) img_bar:Node = null; //无效果一张图
  11. @property(Node) img_pointer:Node = null;
  12. @property(Node) img_text_bing_zhu_hu_xi:Node = null; //无效果一张图
  13. @property(Node) btn_bingxi:Node = null;
  14. @property(Node) lab_time_count:Node = null; //倒计时
  15. private rightLength:number = 200;
  16. private moveLen:number = 50;
  17. private curTime:number = 0;
  18. private time:number = 3;
  19. private mWeiChiPointer:wei_chi_pointer_data = null;
  20. protected init(): void {
  21. this.mWeiChiPointer = this.mTopData._wei_chi_pointer_data;
  22. if(this.mWeiChiPointer===null){
  23. return tools.showToast("指针定位界面编辑错误!")
  24. }
  25. this.rightLength = this.mWeiChiPointer.rightLength;
  26. this.time = this.mWeiChiPointer.time;
  27. this.initWeiChiPointer()
  28. }
  29. initWeiChiPointer(){
  30. this.loadBg(this.mWeiChiPointer.bg)
  31. gameManager.initUiBaseAtt(this.img_hand,this.mWeiChiPointer.img_hand)
  32. gameManager.initUiBaseAtt(this.img_bar,this.mWeiChiPointer.img_bar)
  33. gameManager.initUiBaseAtt(this.img_pointer,this.mWeiChiPointer.img_pointer)
  34. gameManager.initUiBaseAtt(this.img_text_bing_zhu_hu_xi,this.mWeiChiPointer.img_text_bing_zhu_hu_xi)
  35. gameManager.initUiBaseAtt(this.btn_bingxi,this.mWeiChiPointer.btn_bingxi)
  36. this.btn_bingxi.on(Node.EventType.TOUCH_START,this.onClickMove.bind(this))
  37. }
  38. protected onEnable(): void {
  39. this.startRunPoint()
  40. }
  41. stopRunPoint(){
  42. Tween.stopAllByTarget(this.img_pointer)
  43. let r= this.rightLength*0.5;
  44. if(this.img_pointer.position.x>(-r)&&this.img_pointer.position.x<r){
  45. this.onFinishEvent()
  46. console.log("过关成功")
  47. }else{
  48. this.onFialEvent()
  49. console.log("过关失败")
  50. }
  51. }
  52. onClickMove(){
  53. if(this.img_pointer.position.x<(this.img_bar.getComponent(UITransform).contentSize.width*0.5)){
  54. this.img_pointer.position= new Vec3(this.img_pointer.position.x+this.moveLen,this.img_pointer.position.y)
  55. }
  56. }
  57. startRunPoint(){
  58. this.lab_time_count.getComponent(Label).string = `倒计时 ${this.time-this.curTime} 秒`
  59. this.schedule(this.timeCount,1)
  60. this.schedule(()=>{
  61. if(this.img_pointer.position.x>-(this.img_bar.getComponent(UITransform).contentSize.width*0.5)){
  62. this.img_pointer.position= new Vec3(this.img_pointer.position.x-this.moveLen,this.img_pointer.position.y)
  63. }
  64. },0.5)
  65. }
  66. timeCount(){
  67. this.curTime++;
  68. this.lab_time_count.getComponent(Label).string = `倒计时 ${this.time-this.curTime} 秒`
  69. if(this.curTime>=this.time){
  70. this.curTime = 0;
  71. this.unscheduleAllCallbacks()
  72. this.stopRunPoint()
  73. return
  74. }
  75. }
  76. }