home_guangbo.ts 2.1 KB

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