bgscroll.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 = "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. }
  44. let footstep = cc.Canvas.instance.node.getChildByName("footstep")
  45. let footstepcontent = footstep.getChildByName("view").getChildByName("content")
  46. for (let index = 1; index < 444; index++) {
  47. const url = "footstep/footstep" + index
  48. cc.resources.load(url, cc.Prefab, (err, Prefab) => {
  49. if (err) {
  50. return
  51. }
  52. let a = cc.instantiate(Prefab);
  53. a.parent = footstepcontent
  54. a.active = true
  55. a.setContentSize(80, 80)
  56. a.on('touchstart', () => {
  57. if (window['selectNode']) {
  58. let temppp = cc.instantiate(Prefab)
  59. temppp.parent = window['selectNode']
  60. temppp.addComponent(footstepmove)
  61. }
  62. })
  63. });
  64. }
  65. }
  66. }