Parabola.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 = 1002
  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. this.prefab = SubNode
  22. });
  23. }
  24. ChildIndex: number = 0
  25. circle(x: number, y: number) {
  26. if (this.node.children[this.ChildIndex]) {
  27. this.node.children[this.ChildIndex].setPosition(x, y)
  28. this.node.children[this.ChildIndex].active = true
  29. } else {
  30. let temp = cc.instantiate(this.prefab)
  31. temp.parent = this.node
  32. temp.active = true
  33. temp.setPosition(x, y)
  34. }
  35. this.ChildIndex++
  36. }
  37. clear() {
  38. this.ChildIndex = 0
  39. this.node.children.forEach(e => { e.active = false })
  40. }
  41. // update (dt) {}
  42. }