2020-03-31 17:40:54 +00:00
|
|
|
const { ccclass, property } = cc._decorator;
|
2020-03-30 01:50:48 +00:00
|
|
|
|
|
|
|
@ccclass
|
|
|
|
export default class Infinite_bg_scroll extends cc.Component {
|
2020-03-31 17:40:54 +00:00
|
|
|
@property(cc.Node)
|
|
|
|
bg1: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
|
|
bg2: cc.Node = null;
|
2020-03-30 01:50:48 +00:00
|
|
|
|
2020-03-31 17:40:54 +00:00
|
|
|
speed: number = 500;
|
2020-04-01 14:11:08 +00:00
|
|
|
onLoad() {
|
|
|
|
const viewSize = cc.view.getVisibleSize();
|
|
|
|
this.bg2.getComponent(cc.Widget).left = viewSize.width
|
|
|
|
this.bg2.getComponent(cc.Widget).right = -viewSize.width
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:40:54 +00: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 01:50:48 +00:00
|
|
|
}
|
2020-03-31 17:40:54 +00:00
|
|
|
|
|
|
|
this.bg1.x -= temp;
|
|
|
|
this.bg2.x -= temp;
|
|
|
|
}
|
2020-03-30 01:50:48 +00:00
|
|
|
}
|