home_guangbo.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { _decorator, Component, Label, Node, Tween, tween, UITransform, Vec3 } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('home_guangbo')
  4. export class home_guangbo extends Component {
  5. @property(Node) lab_1:Node = null
  6. @property(Node) lab_2:Node = null
  7. private cur_index = 0
  8. private data_list:string[] = ['1','2','3','4']
  9. init() {
  10. // this.setText(this.lab_1, this.data_list[this.cur_index])
  11. // this.schedule(()=>{
  12. // this.cur_index++
  13. // if(this.cur_index>=this.data_list.length) {
  14. // this.cur_index = 0
  15. // }
  16. // this.setText(this.lab_1, this.data_list[this.cur_index])
  17. // },2)
  18. }
  19. private startSchedule() {
  20. // this.lab_2.active = false
  21. this.setText(this.lab_1, this.data_list[this.cur_index])
  22. this.schedule(()=>{
  23. this.cur_index ++
  24. this.runFrame(this.lab_1)
  25. this.runFrame(this.lab_2)
  26. if(this.cur_index>=this.data_list.length) {
  27. this.cur_index = 0
  28. }
  29. },2)
  30. }
  31. private stopSchedule() {
  32. this.unscheduleAllCallbacks()
  33. }
  34. private runFrame(current_node:Node) {
  35. let cur_y = current_node.getPosition().y
  36. tween(current_node).to(0.5,{position: new Vec3(0,cur_y+50,0)},{
  37. }).call(()=>{
  38. let later_y = current_node.getPosition().y
  39. if(later_y==50) {
  40. // current_node.active = false
  41. current_node.setPosition(new Vec3(0,-50,0))
  42. } else if(later_y==0) {
  43. this.setText(current_node, this.data_list[this.cur_index])
  44. current_node.active = true
  45. } else if(later_y==-50) {
  46. current_node.active = false
  47. }
  48. }).start()
  49. }
  50. private setText(current_node:Node, str:string) {
  51. current_node.getComponent(Label).string = '恭喜广州吴彦祖-' + str
  52. }
  53. }