2020-04-02 16:58:36 +00:00
|
|
|
|
import BackHomeBtn from './BackHomeBtn';
|
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
const LOAD_SCENE_MIN_SEC: number = 1.2;
|
2020-03-31 17:40:54 +00:00
|
|
|
|
enum sceneList {
|
2020-05-04 11:18:35 +00:00
|
|
|
|
'Water_spread' = '水波扩散效果(shader)',
|
2020-05-02 08:35:13 +00:00
|
|
|
|
'Specular_gloss' = '镜面光泽效果(shader)',
|
2020-04-25 10:21:00 +00:00
|
|
|
|
'Dissolve_color' = '溶解效果(shader)',
|
2020-05-04 11:18:35 +00:00
|
|
|
|
'Follow_spot' = '追光效果(shader)',
|
2020-05-17 16:00:59 +00:00
|
|
|
|
'Metaball' = '融球效果(shader)',
|
2020-05-04 11:18:35 +00:00
|
|
|
|
'Circle_avatar' = '圆形头像(shader)',
|
2020-04-06 07:06:14 +00:00
|
|
|
|
'Scratch_ticket' = '刮刮卡实现',
|
2020-04-04 16:49:55 +00:00
|
|
|
|
'Coin_fly_to_wallet' = '金币落袋效果',
|
2020-05-04 11:18:35 +00:00
|
|
|
|
'Moving_ghost' = '移动残影效果',
|
2020-04-25 10:21:00 +00:00
|
|
|
|
'Magnifying_mirror' = '放大镜效果',
|
2020-04-05 13:16:36 +00:00
|
|
|
|
'Typer' = '打字机效果',
|
2020-04-25 08:07:43 +00:00
|
|
|
|
'Bullet_Tracking' = '子弹跟踪效果',
|
|
|
|
|
'Infinite_bg_scroll' = '背景无限滚动',
|
|
|
|
|
'Change_clothes' = '换装',
|
2020-04-14 15:57:16 +00:00
|
|
|
|
'Screen_vibrating' = '震屏效果+动画恢复第一帧',
|
2020-05-12 03:40:13 +00:00
|
|
|
|
'Joystick' = '遥控杆',
|
2020-05-28 13:40:16 +00:00
|
|
|
|
'Filter' = '颜色滤镜',
|
2020-06-06 15:54:55 +00:00
|
|
|
|
'Mosaic' = '马赛克/像素风(shader)',
|
|
|
|
|
'Photo_gallery' = '渐变过渡的相册(shader)'
|
2020-03-31 17:40:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ccclass
|
|
|
|
|
export default class Home extends cc.Component {
|
2020-04-02 16:58:36 +00:00
|
|
|
|
@property(cc.Node)
|
|
|
|
|
loadingNode: cc.Node = null;
|
|
|
|
|
@property(cc.ProgressBar)
|
|
|
|
|
loadingProgress: cc.ProgressBar = null;
|
2020-03-31 17:40:54 +00:00
|
|
|
|
@property(cc.Node)
|
|
|
|
|
scrollContent: cc.Node = null;
|
|
|
|
|
@property(cc.Prefab)
|
|
|
|
|
scrollItemPrefab: cc.Prefab = null;
|
|
|
|
|
|
|
|
|
|
onLoad() {
|
|
|
|
|
this.initScrollItem();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 15:13:21 +00:00
|
|
|
|
start() {
|
|
|
|
|
this.judgeJump();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
judgeJump() {
|
2020-04-02 16:58:36 +00:00
|
|
|
|
const sceneName = this.getQueryStringByName('sceneName');
|
|
|
|
|
const isSameVisit = window['isSameVisit'];
|
2020-04-02 15:13:21 +00:00
|
|
|
|
|
|
|
|
|
if (!sceneName) return;
|
|
|
|
|
if (isSameVisit) return;
|
|
|
|
|
|
|
|
|
|
if (sceneList[sceneName]) {
|
2020-04-02 16:58:36 +00:00
|
|
|
|
window['isSameVisit'] = true;
|
2020-04-02 15:13:21 +00:00
|
|
|
|
this.loadScene(sceneName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getQueryStringByName(name) {
|
2020-04-02 16:58:36 +00:00
|
|
|
|
let result = window.location.search.match(new RegExp('[?&]' + name + '=([^&]+)', 'i'));
|
|
|
|
|
return result == null || result.length < 1 ? '' : result[1];
|
2020-04-02 15:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 17:40:54 +00:00
|
|
|
|
initScrollItem() {
|
|
|
|
|
for (let key in sceneList) {
|
|
|
|
|
let scrollItem = cc.instantiate(this.scrollItemPrefab);
|
|
|
|
|
|
2020-04-02 16:58:36 +00:00
|
|
|
|
scrollItem.getChildByName('label').getComponent(cc.Label).string = sceneList[key];
|
|
|
|
|
scrollItem.on(
|
|
|
|
|
cc.Node.EventType.TOUCH_END,
|
|
|
|
|
() => {
|
|
|
|
|
cc.tween(scrollItem)
|
|
|
|
|
.to(0.1, { scale: 1.05 })
|
|
|
|
|
.to(0.1, { scale: 1 })
|
|
|
|
|
.start();
|
|
|
|
|
this.loadScene(key);
|
|
|
|
|
},
|
|
|
|
|
this
|
|
|
|
|
);
|
2020-03-31 17:40:54 +00:00
|
|
|
|
|
|
|
|
|
this.scrollContent.addChild(scrollItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 16:58:36 +00:00
|
|
|
|
beginLoad: boolean = false;
|
|
|
|
|
finishLoadFlag: boolean = false;
|
|
|
|
|
loadTime: number = 0;
|
|
|
|
|
loadSceneName: string = '';
|
2020-03-31 17:40:54 +00:00
|
|
|
|
loadScene(key) {
|
2020-04-02 16:58:36 +00:00
|
|
|
|
if (this.beginLoad) return;
|
|
|
|
|
this.loadingProgress.progress = 0;
|
|
|
|
|
this.loadingNode.active = true;
|
|
|
|
|
this.beginLoad = true;
|
|
|
|
|
this.loadSceneName = key;
|
|
|
|
|
|
|
|
|
|
cc.director.preloadScene(
|
|
|
|
|
key,
|
|
|
|
|
(completedCount, totalCount) => {
|
|
|
|
|
// 还是做假进度条吧,缓存之后太快了,一闪而过的体验不好
|
|
|
|
|
// this.loadingProgress.progress = completedCount / totalCount;
|
|
|
|
|
},
|
|
|
|
|
(error, asset) => {
|
|
|
|
|
if (!error) {
|
|
|
|
|
this.finishLoadFlag = true;
|
|
|
|
|
} else {
|
|
|
|
|
this.loadingNode.active = false;
|
|
|
|
|
this.beginLoad = false;
|
|
|
|
|
this.loadTime = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update(dt) {
|
|
|
|
|
if (!this.beginLoad) return;
|
|
|
|
|
|
|
|
|
|
if (this.loadTime >= LOAD_SCENE_MIN_SEC && this.finishLoadFlag) {
|
|
|
|
|
this.loadingProgress.progress = 1;
|
|
|
|
|
BackHomeBtn.instance.toggleActive(true);
|
|
|
|
|
cc.director.loadScene(this.loadSceneName);
|
|
|
|
|
} else {
|
|
|
|
|
this.loadTime += dt;
|
|
|
|
|
this.loadingProgress.progress = Math.min(this.loadTime / LOAD_SCENE_MIN_SEC, this.finishLoadFlag ? 1 : 0.9);
|
|
|
|
|
}
|
2020-03-31 17:40:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|