weiqi_item.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { _decorator, Component, Node, Tween, tween, Vec3 } from 'cc';
  2. import { weiqi_manager } from './weiqi_manager';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('weiqi_item')
  5. export class weiqi_item extends Component {
  6. private mDur:number = 0
  7. private old_pos:Vec3 = null
  8. public init(){
  9. this.hide()
  10. }
  11. public play(duration: number){
  12. this.mDur = duration
  13. if(this.node.parent!=null){
  14. // let dir = this.node.parent.getComponent(weiqi_manager).getDir()
  15. this.old_pos =this.node.parent.getComponent(weiqi_manager).getOriginPos()
  16. this.node.position = new Vec3(this.old_pos.x,this.old_pos.y)
  17. // let nor = pos.subtract(dir).normalize()
  18. // let ndir = nor.multiplyScalar(dis)
  19. tween(this.node).delay(duration).call(()=>{
  20. this.show()
  21. this.old_pos=null
  22. this.play(this.mDur)
  23. })
  24. // .to(duration,{position:dir}).call(()=>{
  25. // this.hide()
  26. // this.play(this.mDur)
  27. // })
  28. .start()
  29. }
  30. }
  31. hide(){
  32. this.node.active = false
  33. }
  34. show(){
  35. this.node.active = true
  36. }
  37. protected onDestroy(): void {
  38. Tween.stopAllByTarget(this.node)
  39. }
  40. protected update(dt: number): void {
  41. if(this.old_pos!=null){
  42. this.node.position = new Vec3(this.node.position.x,this.node.position.y-dt*100)
  43. if(Vec3.distance(this.node.position,this.old_pos)>150){
  44. this.hide()
  45. }
  46. }
  47. }
  48. }