rankCtr.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { _decorator, Component, Label, Node, tween, Vec3 } from "cc"
  2. const { ccclass, property } = _decorator
  3. @ccclass("rankCtr")
  4. export class rankCtr extends Component {
  5. @property({ type: Node })
  6. public textLiveRank: Node | null = null
  7. @property({ type: Node })
  8. public rankNods: Node[] = []
  9. @property({ type: Node })
  10. public textPointsRank: Node | null = null
  11. private isLiveRank: boolean = true
  12. private moveDistance: number = -150
  13. private lng:string = 'cn'
  14. start() {}
  15. // 触发方法
  16. updateRankTop() {
  17. this.isLiveRank = !this.isLiveRank
  18. this.updateRankDisplay()
  19. }
  20. private updateRankDisplay() {
  21. if (!this.textLiveRank || !this.textPointsRank) return
  22. let moveOffset = this.isLiveRank ? -this.moveDistance : this.moveDistance
  23. let moveAction = new Vec3(moveOffset, 0, 0)
  24. tween(this.textLiveRank).by(0.5, { position: moveAction }).start()
  25. tween(this.textPointsRank).by(0.5, { position: moveAction }).start()
  26. }
  27. updateRank(data:any[])
  28. {
  29. for(let i=0;i<6;i++)
  30. {
  31. const nameLebel= this.rankNods[i].getChildByName("text_player_name").getComponent(Label);
  32. const days= this.rankNods[i].getChildByName("text_value").getComponent(Label);
  33. if(data.length > i)
  34. {
  35. nameLebel.string = data[i].userInfo.name
  36. if(this.lng === 'cn')
  37. {
  38. days.string = data[i].survival + '天'
  39. }
  40. else{
  41. days.string = data[i].survival + (data[i].survival == '1' ? 'day' : 'days' )
  42. }
  43. }
  44. }
  45. }
  46. update(deltaTime: number) {}
  47. }