Egret Launcher 引擎入门教学笔记(五)

98 阅读2分钟

一·.新建设置的GameSetting组件

  • 构建GameSetting.exml

  • 资源加载

    public constructor() {
    	//加载所有的音频
    	this.click_sound = new egret.Sound();
    	this.click_sound.load("resource/assets/data/Sound/buttonclick.mp3");
    	this.bgm_sound = new egret.Sound();
    	this.bgm_sound.load("resource/assets/data/Sound/Music.mp3");
    	this.right_sound = new egret.Sound();
    	this.right_sound.load("resource/assets/data/Sound/right.mp3");
    	this.wrong_sound = new egret.Sound();
    	this.wrong_sound.load("resource/assets/data/Sound/wrong.mp3");
    	this.word_sound = new egret.Sound();
    	this.word_sound.load("resource/assets/data/Sound/type_word.mp3");
    
    	// console.log(this.click_sound)
    }
    
  • 本地存储(保存的用户设置音乐/音频) 

    //播放bgm音乐 public playBgm() { if (this.isMsuic) { this.bgm_channel = this.bgm_sound.play(0, 0); } }

    //停止播放音乐
    public stopBgm() {
    	if (this.bgm_channel != null) {
    		this.bgm_channel.stop();
    	}
    }
    //音频播放
    public playClick() {
    	if (this.isSound) {
    		this.click_sound.play(0, 1);
    	}
    }
    // 成功的音频
    public playRight() {
    	if (this.isSound) {
    		this.right_sound.play(0, 1);
    	}
    }
    
    //失败的音频
    public playWorng() {
    	if (this.isSound) {
    		this.wrong_sound.play(0, 1);
    	}
    }
    // 文字的音频
    public playWord() {
    	if (this.isSound) {
    		this.word_sound.play(0, 1);
    	}
    }
    
    // 音乐是否播放
    public set isMsuic(val) {
    	if (!val) {
    		egret.localStorage.setItem('isMsuic', "0");
    		 this.stopBgm();
    	} else {
    		egret.localStorage.setItem('isMsuic', "1");
    		this.playBgm();
    	}
    
    }
    
    public get isMsuic() {
    	var b = egret.localStorage.getItem('isMsuic');
    	if (b == null || b == "") {
    		return true;
    	} else {
    		return b == "1";
    	}
    }
    
    public set isSound(val) {
    	if (val) {
    		egret.localStorage.setItem('isSound', "1");
    	} else {
    		egret.localStorage.setItem('isSound', "0");
    	}
    }
    
    public get isSound() {
    	var b = egret.localStorage.getItem('isSound');
    	if (b == null || b == "") {
    		return true;
    	} else {
    		return b == "1";
    	}
    }
    

项目串联

一 .游戏开始场景

  • 设置按钮->进入游戏设置场景
  • 开始游戏按钮->进入游戏关卡场景

二.游戏的设置场景

  • 音乐/音效的按钮->打开ho've禁用音乐/音效播放

  • 禁用状态的图片要设置touchEnable = false;

  • 确定按钮->关闭设置场景

  • 游戏设置.上镜直接添加,而不需要把游戏开始场景隐藏

 三.游戏关卡选择场景

  • 背景图
  • 关卡按钮的动态添加
  • 关卡按钮的sin正弦函数曲线布局
  • 关卡的按钮的状态管理
  • 最远关卡的存档/读档
  • 指示箭头的位置(指向当前选择的关卡)
  • 返回按钮-> 游戏开始场景
  • 关卡按钮->游戏场景

 四游戏场景

  • 返回按钮-> 游戏关卡选择场景

  • 答案区域

  • 提示图

  • 答案成语(answerWord)

  • 选择区域

  • 20个字组成(当前关卡的答案成语(4个字)+当前关卡的混淆字(6个字) +随机-个关卡的10个字)

  • 20个字需要重新打乱顺序排列.

  • word

  • 点击事件

  • 让自身隐藏(让点击的文字内容出现在空白的答案区.)

  • 把自身(Word)传递给答案区响应的(answerWord)->为点击答案区的文字,让其内容显示做准备.

  • 验证答案区是否正确(答案区组成的成语==关卡的answer)->显示游戏的正解场景

五游戏的正解场景

  •  成语解释

  • 成语出处

  • 下一关

  • 点击事件

  • 让游戏正解场景隐藏调用游戏场景的初始化方法,把下一关的数据渲染出来告诉游戏关卡选择场景,记录(存档)最远关卡. 包括游戏最远关卡存档过关关卡的状态改变知识箭头的重新布局