LayaAir飞机大战-7

  1. 用LayaAirIDE制作游戏暂停、关卡、积分、血量等UI界面.

  1. 用游戏代码来实现对UI的控制并且优化之前到逻辑.

/**

* 游戏UI类

*/

class GameInfo extends ui.GameInfoUI {

constructor() {

super();

//注册按钮点击事件,点击之后暂停游戏

this.pauseBtn.on(Laya.Event.CLICK,this,this.onPauseBtnClick);

//初始化UI显示

this.reset();

}

public reset():void{

this.infoLabel.text = "";

this.hp(5);

this.level(0);

this.score(0);

}

onPauseBtnClick(e:Laya.Event):void{

//阻止事件冒泡

e.stopPropagation();

//暂停游戏

this.infoLabel.text = "游戏已暂停,点击任意地方恢复游戏";

gameInstance.pause();

Laya.stage.once(Laya.Event.CLICK,this,this.onStageClick);

}

onStageClick(e:Laya.Event):void{

this.infoLabel.text = "";

gameInstance.resume();

}

//显示血量

public hp(value:number):void{

this.hpLabel.text = "HP:"+value;

}

//显示关卡级别

public level(value:number):void{

this.levelLabel.text = "Level:"+value;

}

//显示积分

public score(value:number):void{

this.scoreLabel.text = "Score:"+value;

}

}

 

/**

*主程序

*/

restart():void{

//重置游戏数据

this.score = 0;

this.level = 0;

this.levelUpScore = 10;

this.bulletLevel = 0;

this.gameInfo.reset();

 

//初始化角色

this.hero.init("hero",0,5,0,30);

//设置射击类型

this.hero.shootType = 1;

//设置角色位置

this.hero.pos(200,500);

//重置射击间隔

this.hero.shootInterval = 500;

//显示角色

this.hero.visible = true;

 

for(var i:number = this.roleBox.numChildren-1;i>-1;i--){

var role:Role = this.roleBox.getChildAt(i) as Role;

if(role != this.hero){

role.removeSelf();

//回收之前重置的信息

role.visible = true;

//回收到对象池

Laya.Pool.recover("role",role);

}

}

this.resume();

}

//暂停

public pause():void{

//停止游戏主循环

Laya.timer.clear(this,this.onLoop);

//移除舞台的鼠标移动事件

Laya.stage.off(Laya.Event.MOUSE_MOVE,this,this.onMouseMove);

}

//恢复

public resume():void{

//创建游戏主循环

Laya.timer.frameLoop(1,this,this.onLoop);

//监听舞台的鼠标移动事件

Laya.stage.on(Laya.Event.MOUSE_MOVE,this,this.onMouseMove);

}

  1. 给游戏添加音效

相应到地方调用Laya.SoundManager.playSound

//播放爆炸动画弹声音

Laya.SoundManager.playSound("res/sound/"+role.type+"_down.mp3");

  1. 增加屏幕适配

//设置适配模式

Laya.stage.scaleMode = "showall";

//设置居中对齐

Laya.stage.alignH = "center";

//设置横竖屏

Laya.stage.screenMode = "vertical";

 

完整源代码已上传

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值