Parabola.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class Parabola extends cc.Component {
  10. ParabolaID: number = 1000
  11. prefab: cc.Node = null
  12. start() {
  13. const url = `Parabola/${this.ParabolaID}`
  14. cc.resources.load(url, cc.SpriteFrame, (err, SpriteFrame) => {
  15. if (err) {
  16. return
  17. }
  18. let SubNode = new cc.Node()
  19. SubNode.addComponent(cc.Sprite).spriteFrame = SpriteFrame
  20. SubNode.setAnchorPoint(0.5, 0.5)
  21. SubNode.setScale(0.8)
  22. this.prefab = SubNode
  23. });
  24. }
  25. ChildIndex: number = 0
  26. circle(x: number, y: number) {
  27. if (this.node.children[this.ChildIndex]) {
  28. this.node.children[this.ChildIndex].setPosition(x, y)
  29. this.node.children[this.ChildIndex].active = true
  30. } else {
  31. let temp = cc.instantiate(this.prefab)
  32. temp.parent = this.node
  33. temp.active = true
  34. temp.setPosition(x, y)
  35. }
  36. this.ChildIndex++
  37. }
  38. clear() {
  39. this.ChildIndex = 0
  40. this.node.children.forEach(e => { e.active = false })
  41. }
  42. // update (dt) {}
  43. }