12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import { _decorator, Component, Label, Node, Tween, tween, UITransform, Vec3 } from 'cc';
- import { guangboData } from '../../data';
- const { ccclass, property } = _decorator;
- @ccclass('home_guangbo')
- export class home_guangbo extends Component {
- @property(Node) lab_1:Node = null
- @property(Node) lab_2:Node = null
- private cur_index = 0
- private data_list:guangboData[] = []
- init(data_list:guangboData[]) {
- this.data_list = data_list
- this.lab_1.getComponent(Label).string = this.data_list[this.cur_index].title
- this.unscheduleAllCallbacks()
- this.schedule(()=>{
- this.cur_index++
- if(this.cur_index>=this.data_list.length) {
- this.cur_index = 0
- }
- this.lab_1.getComponent(Label).string = this.data_list[this.cur_index].title
- },2.5)
- }
- private startSchedule() {
- // this.lab_2.active = false
- this.setText(this.lab_1, this.data_list[this.cur_index].title)
- this.schedule(()=>{
- this.cur_index ++
- this.runFrame(this.lab_1)
- this.runFrame(this.lab_2)
- if(this.cur_index>=this.data_list.length) {
- this.cur_index = 0
- }
- },2.5)
- }
- private stopSchedule() {
- this.unscheduleAllCallbacks()
- }
- private runFrame(current_node:Node) {
- let cur_y = current_node.getPosition().y
- tween(current_node).to(0.5,{position: new Vec3(0,cur_y+50,0)},{
- }).call(()=>{
- let later_y = current_node.getPosition().y
- if(later_y==50) {
- // current_node.active = false
- current_node.setPosition(new Vec3(0,-50,0))
- } else if(later_y==0) {
- this.setText(current_node, this.data_list[this.cur_index].title)
- current_node.active = true
- } else if(later_y==-50) {
- current_node.active = false
- }
- }).start()
- }
- private setText(current_node:Node, str:string) {
- current_node.getComponent(Label).string = '恭喜广州吴彦祖-' + str
- }
- }
|