28 lines
638 B
TypeScript
Raw Normal View History

2020-04-01 01:40:54 +08:00
const { ccclass, property } = cc._decorator;
2020-03-30 09:50:48 +08:00
@ccclass
export default class Infinite_bg_scroll extends cc.Component {
2020-04-01 01:40:54 +08:00
@property(cc.Node)
bg1: cc.Node = null;
@property(cc.Node)
bg2: cc.Node = null;
2020-03-30 09:50:48 +08:00
2020-04-01 01:40:54 +08:00
speed: number = 500;
2020-04-01 22:11:08 +08:00
onLoad() {
const viewSize = cc.view.getVisibleSize();
this.bg2.getComponent(cc.Widget).left = viewSize.width
this.bg2.getComponent(cc.Widget).right = -viewSize.width
}
2020-04-01 01:40:54 +08:00
update(dt) {
const temp = dt * this.speed;
if (this.bg2.x - temp <= 0) {
this.bg1.x = this.bg2.x;
this.bg2.x = this.bg1.x + this.bg1.width;
2020-03-30 09:50:48 +08:00
}
2020-04-01 01:40:54 +08:00
this.bg1.x -= temp;
this.bg2.x -= temp;
}
2020-03-30 09:50:48 +08:00
}