egret 音乐播放

egret 音乐播放播放背景音乐 exportlet curBgMusic egret Sound null exportlet curBgMusicUr string null exportlet curBgMusicCh egret SoundChannel null exportfuncti url

 // 播放背景音乐 export let _curBgMusic:egret.Sound = null; export let _curBgMusicUrl:string = null; export let _curBgMusicChannel:egret.SoundChannel = null; export function playBgMusic(url) { 
    if (!mo.PROJ.bgMusicEnabled) return; if (_curBgMusicUrl == url) return; _curBgMusicUrl = url; if (_curBgMusicChannel) _curBgMusicChannel.stop(); mo.R.loadTo('global', url, function () { 
    if (_curBgMusicChannel) _curBgMusicChannel.stop(); console.log(url); _curBgMusic = mo.R.get(url); if (_curBgMusic) { _curBgMusicChannel = _curBgMusic.play(); _curBgMusicChannel.volume = 0.6; } }); } //播放音效 export let _curOneEffectChannel:egret.SoundChannel = null;//共用一个声道 export function playEffect(url, isShareOne:boolean = false) { 
    if (!mo.PROJ.effectEnabled) return null; if (_curOneEffectChannel && isShareOne) _curOneEffectChannel.stop(); let effect:egret.Sound = null; mo.R.loadTo('global', url, function () { 
    console.log(url); effect = mo.R.get(url); if (effect) { if (isShareOne) { _curOneEffectChannel = effect.play(0, 1); } else { effect.play(0, 1); } } }); } export function initBgMusic(stage) { 
    // 激活的时候 stage.addEventListener(egret.Event.ACTIVATE, function () { 
    if (!mo.PROJ.bgMusicEnabled) return; if (_curBgMusicChannel) _curBgMusicChannel.stop(); if (_curBgMusic) _curBgMusicChannel = _curBgMusic.play(); }, null); stage.addEventListener(egret.Event.DEACTIVATE, function () { 
    if (!mo.PROJ.bgMusicEnabled) return; if (_curBgMusicChannel) _curBgMusicChannel.stop(); }, null); }

本地存储,配置表?

 export var bgMusicEnabled:boolean = true; export var effectEnabled:boolean = true; if (egret.localStorage.getItem("bgMusicEnabled")) { bgMusicEnabled = egret.localStorage.getItem("bgMusicEnabled") == "true" ? true : false; } else { egret.localStorage.setItem("bgMusicEnabled", "true"); bgMusicEnabled = true; } if (egret.localStorage.getItem("effectEnabled")) { effectEnabled = egret.localStorage.getItem("effectEnabled") == "true" ? true : false; } else { egret.localStorage.setItem("effectEnabled", "true"); effectEnabled = true; } registerValueHandler(function (data) { 
    setValue(data, 'bgMusicEnabled', bgMusicEnabled); setValue(data, 'effectEnabled', effectEnabled);
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/232480.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • UFT如何在谷歌浏览器上实现录制

    UFT如何在谷歌浏览器上实现录制https://user.qzone.qq.com/305132437/blog/1395738617?t=0.748526355385565https://user.qzone.qq.com/305132437/blog/14097396271.UFT安装目录\bin\Chrome,找到Agent.crx,复制2.拷贝到win7系统啊C:\Users\用户\AppData\Local\…

    2022年5月28日
    76
  • 手机运行的python_运行python程序的两种方式

    手机运行的python_运行python程序的两种方式前言在手机上运行Python需要用一个软件,叫QPython3L,当然还有别的软件也是可以运行Python的,不过我认为QPython3L是其中相对较好的一个。首先声明一下,我也只是会简单的使用有了它,就可以实现用手机和电脑进行通信了,比如在手机用Socket给电脑发指令,电脑根据收到的指令去执行不同的函数。苹果手机有没有我也不知道,可以自己搜一下如何下载我是在酷安下的,直接搜索qpython3即…

    2022年8月12日
    6
  • IDS入侵检测系统的缺点_IDS入侵检测是指依照

    IDS入侵检测系统的缺点_IDS入侵检测是指依照[转载自:https://blog.csdn.net/qq_36119192/article/details/84343269]一、IDS是什么IDS(intrusiondetectionsystem)入侵检测系统是一种对网络传输进行即时监视,在发现可疑传输时发出警报或者采取主动反应措施的网络安全设备。它与其他网络安全设备的不同之处便在于,IDS是一种积极主动的安全防护技术。在很多中大…

    2022年10月9日
    3
  • 全国计算机三级数据库技术

    全国计算机三级数据库技术全国计算机等级考试三级(数据库技术)一:考试内容及要求1.掌握数据库技术的基本概念、原理、方法和技术2.能够使用SQL语言实现数据库操作3.具备数据库系统安装、配置及数据库管理和维护的基本4.掌握数据库管理与维护的基本方法5.掌握数据库性能优化的基本方法6.了解数据库应用系统的生命周期及其设计、开发过程7.熟悉常用的数据库管理和开发工具、具备用指定的工具管理、开发简单数据库应用系统…

    2022年6月18日
    18
  • GFS – The Google File System

    GFS – The Google File SystemTheGoogleFileSystemhttp://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.125.789&rep=rep1&type=pdfhttp://www.dbthink.com/?p=501,中文翻译 Google牛人云集的地方,但在设计系统时,却非常务实,没有采用什么复杂和时髦…

    2022年6月1日
    33
  • linux中安装pycharm_ubuntu激活成功教程pycharm

    linux中安装pycharm_ubuntu激活成功教程pycharm前言由于学习需要,准备开始在linux环境下使用python。一开始是使用了vim作为编译器的,我承认vim确实很简洁,然而对于我这种新手来说确实是很低效,一开始用vim写代码真的是让我重新体会了一遍VC手撸C语言的感觉,而且面对了还是tf这种函数巨多的库。因此还是转去用了pycharm,可能我注定和大神无缘吧,逼格都提升不到。这篇文章主要介绍linux下的安装、环境配置和学生优惠。安装…

    2022年8月28日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号