weiqi_manager.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { _decorator, Component, instantiate, Node, Prefab, UITransform, Vec2, Vec3 } from 'cc';
  2. import { weiqi_item } from './weiqi_item';
  3. import { car } from '../car';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('weiqi_manager')
  6. export class weiqi_manager extends Component {
  7. @property(Prefab) weiqi_pf:Prefab = null
  8. private mCar:car = null
  9. private COUNT:number = 10
  10. public init(car:car){
  11. this.mCar = car
  12. this.node.removeAllChildren()
  13. for (let index = 0; index < this.COUNT; index++) {
  14. let node = instantiate(this.weiqi_pf)
  15. node.parent = this.node
  16. node.getComponent(weiqi_item).hide()
  17. }
  18. }
  19. public getDir(){
  20. let car_world_p = this.mCar.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.mCar.node.position)
  21. let car_in_effect_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(car_world_p)
  22. let dir = new Vec3(car_in_effect_p.x,car_in_effect_p.y-300)
  23. return dir
  24. }
  25. public getOriginPos(){
  26. // let car_world_p = this.mCar.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.mCar.node.position)
  27. // let car_in_effect_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(car_world_p)
  28. // let dir = new Vec3(car_in_effect_p.x,car_in_effect_p.y-this.mCar.node.getComponent(UITransform).contentSize.height*0.5)
  29. // return dir
  30. return new Vec3(this.mCar.node.position.x,this.mCar.node.position.y-this.mCar.spr.getComponent(UITransform).contentSize.height*0.5)
  31. }
  32. public startEffect(){
  33. for (let index = 0; index < this.node.children.length; index++) {
  34. const node = this.node.children[index];
  35. node.getComponent(weiqi_item).play(index*0.1)
  36. }
  37. }
  38. // protected update(dt: number): void {
  39. // this.node.position = new Vec3(0,this.mCar.node.parent.position.y)
  40. // }
  41. }