import MoreLevelItem from "./MoreLevelItem";
|
import Global from "./Global";
|
|
const {ccclass, property} = cc._decorator;
|
|
@ccclass
|
export default class MoreLevelSlide extends cc.Component {
|
@property(cc.Node)
|
contentNode: cc.Node = null;
|
|
@property(cc.Node)
|
scrollContent: cc.Node = null;
|
|
@property(cc.Prefab)
|
moreLevelPrefab: cc.Prefab = null;
|
|
private isMoving: boolean = false;
|
private movingTime: number = 0.3;
|
|
onLoad(){
|
for(let i = 0; i < Global.MAX_MORE_LEVELS; i++){
|
let node = cc.instantiate(this.moreLevelPrefab);
|
node.active = true;
|
this.scrollContent.addChild(node);
|
|
let item = node.getComponent(MoreLevelItem);
|
item.init(i);
|
}
|
}
|
|
onEnable(){
|
this.show()
|
}
|
|
moveStart(){
|
this.isMoving = true;
|
}
|
|
moveEnd(){
|
this.isMoving = false;
|
}
|
|
// update (dt) {}
|
|
onClickClose(){
|
if (this.isMoving) {
|
return;
|
}
|
|
this.hide();
|
}
|
|
hide(){
|
this.contentNode.runAction(
|
cc.sequence(
|
cc.callFunc(this.moveStart, this),
|
cc.moveTo(this.movingTime, cc.v2(-500, 0)),
|
cc.callFunc(this.hideSelf, this),
|
cc.callFunc(this.moveEnd, this)
|
)
|
);
|
}
|
|
hideSelf(){
|
this.node.active = false;
|
|
}
|
|
show(){
|
this.contentNode.position = cc.v2(-500, 0);
|
this.contentNode.runAction(
|
cc.sequence(
|
cc.callFunc(this.moveStart, this),
|
cc.moveTo(this.movingTime, cc.v2()),
|
cc.callFunc(this.moveEnd, this)
|
)
|
);
|
|
}
|
}
|