NewScript.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import edLayout from "./edLayout";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class NewClass extends cc.Component {
  11. @property(cc.Node)
  12. MapNode: cc.Node = null;
  13. @property
  14. text: string = 'hello';
  15. // LIFE-CYCLE CALLBACKS:
  16. onLoad() {
  17. // 获取当前节点
  18. var node = this.node;
  19. // 为当前节点添加鼠标滑轮事件监听
  20. node.on('mousewheel', this.onMouseWheel, this);
  21. }
  22. onMouseWheel(event) {
  23. // event.getScrollY() 返回1如果滚动向下,-1如果滚动向上
  24. var scrollDirection = event.getScrollY();
  25. if (scrollDirection > 0) {
  26. // up
  27. if (this.MapNode.scale <= 0.1) {
  28. } else {
  29. this.MapNode.scale = this.MapNode.scale - 0.1
  30. if (this.MapNode.scale < 0.1) {
  31. this.MapNode.scale = 0.1
  32. } else {
  33. }
  34. }
  35. } else {
  36. // down
  37. this.MapNode.scale = this.MapNode.scale + 0.1
  38. }
  39. }
  40. protected start(): void {
  41. let Layout = this.node.getChildByName("New Layout").getComponent(edLayout)
  42. let heng = this.node.getChildByName("heng")
  43. let shu = this.node.getChildByName("shu")
  44. let hengButton = heng.getChildByName("New Button")
  45. let EditBox = heng.getChildByName("New EditBox").getComponent(cc.EditBox)
  46. hengButton.on('touchstart', () => {
  47. Layout.initx(parseInt(EditBox.string))
  48. })
  49. // for (let index = 1; index < 10; index++) {
  50. // if (index == 1) {
  51. // let Label = hengButton.getChildByName("Background").getChildByName("Label")
  52. // Label.getComponent(cc.Label).string = "" + index
  53. // hengButton.on('touchstart', () => {
  54. // console.log(index);
  55. // Layout.initx(index)
  56. // })
  57. // continue
  58. // } else {
  59. // let temp = cc.instantiate(hengButton)
  60. // temp.parent = heng
  61. // let Label = temp.getChildByName("Background").getChildByName("Label")
  62. // Label.getComponent(cc.Label).string = "" + index
  63. // temp.on('touchstart', () => {
  64. // console.log(index);
  65. // Layout.initx(index)
  66. // })
  67. // }
  68. // }
  69. let shuButton = shu.getChildByName("New Button")
  70. let EditBox1 = shu.getChildByName("New EditBox").getComponent(cc.EditBox)
  71. shuButton.on('touchstart', () => {
  72. Layout.inity(parseInt(EditBox1.string))
  73. })
  74. // for (let index = 1; index < 10; index++) {
  75. // if (index == 1) {
  76. // let Label = shuButton.getChildByName("Background").getChildByName("Label")
  77. // Label.getComponent(cc.Label).string = "" + index
  78. // shuButton.on('touchstart', () => {
  79. // console.log(index);
  80. // Layout.inity(index)
  81. // })
  82. // continue
  83. // } else {
  84. // let temp = cc.instantiate(shuButton)
  85. // temp.parent = shu
  86. // let Label = temp.getChildByName("Background").getChildByName("Label")
  87. // Label.getComponent(cc.Label).string = "" + index
  88. // temp.on('touchstart', () => {
  89. // console.log(index);
  90. // Layout.inity(index)
  91. // })
  92. // }
  93. // }
  94. let xuanzhuan = this.node.getChildByName("xuanzhuan")
  95. let xuanzhuanButton = xuanzhuan.getChildByName("New Button")
  96. let EditBoxxuanzhuan = xuanzhuan.getChildByName("New EditBox").getComponent(cc.EditBox)
  97. xuanzhuanButton.on('touchstart', () => {
  98. console.log(parseInt(EditBoxxuanzhuan.string));
  99. if (window['selectfootstep']) {
  100. window['selectfootstep'].setRotation(parseInt(EditBoxxuanzhuan.string))
  101. }
  102. })
  103. let suofang = this.node.getChildByName("suofang")
  104. let suofangButton = suofang.getChildByName("New Button")
  105. let EditBoxsuofang = suofang.getChildByName("New EditBox").getComponent(cc.EditBox)
  106. suofangButton.on('touchstart', () => {
  107. console.log(parseInt(EditBoxsuofang.string));
  108. if (window['selectfootstep']) {
  109. window['selectfootstep'].setScale(parseInt(EditBoxsuofang.string))
  110. }
  111. })
  112. }
  113. }