目标:游戏复活页,跑通游戏流程
laya商业级3d游戏开发
初始化页->首页->游戏页->结束页->首页
新建 页面 over.scene
摆好ui
新建views\OverView.ts
export default class OverView extends BaseView {
constructor() {
super();
}
reborn: Laya.Image
no: Laya.Image
onAwake() {
super.onAwake()
}
onOpened(data) {
Utils.addClickEvent(this.reborn, this, this.rebornclick);
Utils.addClickEvent(this.no, this, this.noclick);
//广告组件
BannerAndVideo1.OpenBanner()
}
rebornclick() {
console.log('Onrebornlick');
BannerAndVideo1.ShowVideo(this, (isok) => {
if (isok) {
Game.instance.charactercontroller.Reborn();
this.close()
}
})
//Game.instance.charatercontroller.Reborn();
// this.close()
}
noclick() {
console.log('noclick');
Game.instance.scene.destroy(true)
this.close()
GameSample.GotoHome();
}
onClosed() {
BannerAndVideo1.Clear()
}
}
ViewMgr.ts
增加打开结束页
public OpenOver() {
Laya.Scene.open(SceneType.Over, false, Laya.Handler.create(this, view => {
let s = view as OverView;
}));
}
Player.ts
Fail()
添加
ViewMgr.instance.OpenOver();
增加复活方法
Reborn() {
this.animator.crossFade(‘Cat_RunLong’, 0.2);
Game.instance.speed = 0.3
}
流程控制:
新建初始化页面InitView和InitView.ts
//为什么?
//初始化页面往往用来做后台数据初始化加载逻辑
export default class InitView extends BaseView {
onAwake() {
super.onAwake()
GameSample.GotoHome();
}
}
Main.ts
onConfigLoaded(): void {
let node = new Laya.Node();
Laya.stage.addChild(node);
node.addComponent(UnityEnagine);
Platform.setplatformInfo();
Laya.SoundManager.autoReleaseSound = false;
GameConfig.startScene && Laya.Scene.open(GameConfig.startScene);
return;
}
HomeView.ts
OnStartImageClick() {
console.log(‘OnStartImageClick’);
GameSample.StartGame();
this.scene3D.destroy(true);
this.close();
}
游戏结束时删除游戏界面
Game.ts
onDestroy()
GameView.instance.destroy();
项目设置起始场景调整为初始化页
F8 shift+f12(发布) f5