bgscroll.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 footstepmove from "./footstepmove";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class NewClass extends cc.Component {
  11. @property(cc.Label)
  12. label: cc.Label = null;
  13. @property
  14. text: string = 'hello';
  15. // LIFE-CYCLE CALLBACKS:
  16. onLoad() {
  17. // let item = this.node.getChildByName("view").getChildByName("content").getChildByName("item")
  18. // item.on('click', () => {
  19. // console.log(item.name);
  20. // }, this)
  21. }
  22. start() {
  23. let content = this.node.getChildByName("view").getChildByName("content")
  24. let bgprefabs = this.node.getChildByName("view").getChildByName("bg1")
  25. for (let index = 1; index < 444; index++) {
  26. const url = "res/bg/bg" + index
  27. // cc.resources.load(url, cc.SpriteFrame, (err, spriteframe) => {
  28. // if (err) {
  29. // return
  30. // }
  31. // let a = cc.instantiate(bgprefabs);
  32. // let sprite = a.getComponent(cc.Sprite);
  33. // a.parent = content
  34. // a.active = true
  35. // sprite.spriteFrame = spriteframe;
  36. // a.on('touchstart', () => {
  37. // if (window['selectNode']) {
  38. // let tempSprite = window['selectNode'].getComponent(cc.Sprite) as cc.Sprite
  39. // tempSprite.spriteFrame = spriteframe
  40. // }
  41. // })
  42. // });
  43. let bundle = cc.assetManager.getBundle("sub");
  44. bundle.load(url, cc.SpriteFrame, (err: Error, spriteframe: cc.SpriteFrame) => {
  45. if (err) {
  46. return
  47. }
  48. let a = cc.instantiate(bgprefabs);
  49. let sprite = a.getComponent(cc.Sprite);
  50. a.parent = content
  51. a.active = true
  52. sprite.spriteFrame = spriteframe;
  53. a.on('touchstart', () => {
  54. if (window['selectNode']) {
  55. let tempSprite = window['selectNode'].getComponent(cc.Sprite) as cc.Sprite
  56. tempSprite.spriteFrame = spriteframe
  57. }
  58. })
  59. });
  60. }
  61. let footstep = cc.Canvas.instance.node.getChildByName("footstep")
  62. let footstepcontent = footstep.getChildByName("view").getChildByName("content")
  63. for (let index = 0; index < 3000; index++) {
  64. const url = "res/footstep/footstep" + index
  65. // cc.resources.load(url, cc.Prefab, (err, Prefab) => {
  66. // if (err) {
  67. // return
  68. // }
  69. // let a = cc.instantiate(Prefab);
  70. // a.parent = footstepcontent
  71. // a.active = true
  72. // a.setContentSize(80, 80)
  73. // a.on('touchstart', () => {
  74. // console.log(1);
  75. // if (window['selectNode']) {
  76. // let temppp = cc.instantiate(Prefab)
  77. // temppp.parent = window['selectNode']
  78. // temppp.addComponent(footstepmove)
  79. // }
  80. // })
  81. // });
  82. let bundle = cc.assetManager.getBundle("sub");
  83. bundle.load(url, cc.Prefab, (err: Error, Prefab) => {
  84. if (err) {
  85. return
  86. }
  87. let a = cc.instantiate(Prefab);
  88. a.parent = footstepcontent
  89. a.active = true
  90. a.setContentSize(80, 80)
  91. a.on('touchstart', () => {
  92. console.log(1);
  93. if (window['selectNode']) {
  94. let temppp = cc.instantiate(Prefab)
  95. temppp.parent = window['selectNode']
  96. temppp.addComponent(footstepmove)
  97. }
  98. })
  99. });
  100. }
  101. }
  102. }