首页 » 网站推广 » phpthirdscripterror技巧_手把手Egret若安在微信小游戏创建ComboBox控件

phpthirdscripterror技巧_手把手Egret若安在微信小游戏创建ComboBox控件

访客 2024-11-17 0

扫一扫用手机浏览

文章目录 [+]

在GitHub上搜索egret-game-library,将全体项目以Zip压缩包下载到本地,解压打开。

打开euiextension\ComboBox\libsrc文件夹。
如下图:

phpthirdscripterror技巧_手把手Egret若安在微信小游戏创建ComboBox控件

Egret的ComboBox扩展控件

phpthirdscripterror技巧_手把手Egret若安在微信小游戏创建ComboBox控件
(图片来自网络侵删)

在Egret全体项目的文件夹外,创建一个名为EgretLibs的文件夹。
如果你的项目叫EgretDemo1,路径为D:\Project\EgretProjects\EgretDemo1,那么EgretLibs的路径应为:

D:\Project\EgretProjects\EgretLibs

在EgretLibs文件夹内再创建一个combobox文件夹,然后将上图的所有文件文件夹都复制到这里。

然后修正Egret项目的egretProperties.json文件,在modules节点末了添加如下内容:

{"name": "combobox","path": "../EgretLibs/combobox"}

编译之后,该当在项目的libs/modules文件夹看到天生的combobox文件夹,代表引用成功。

假设游戏的设置页面如下:

小游戏的设置页面

那么对应的页面逻辑代码:

private operationRangeData: any[] = []; private operationRangeMaxCB: ComboBox;private operationRangeLabel: eui.Label; protected childrenCreated(): void { super.childrenCreated(); this.operationRangeData.push({ bg: "itemBg1_png", content: "0" }); this.operationRangeData.push({ bg: "itemBg2_png", content: "5" }); this.operationRangeData.push({ bg: "itemBg1_png", content: "10" }); this.operationRangeData.push({ bg: "itemBg2_png", content: "15" }); this.operationRangeData.push({ bg: "itemBg1_png", content: "20" }); this.operationRangeData.push({ bg: "itemBg2_png", content: "30" }); this.operationRangeData.push({ bg: "itemBg1_png", content: "50" }); this.operationRangeData.push({ bg: "itemBg2_png", content: "100" }); this.operationRangeMaxCB = this.CreateComboBox(this.operationRangeLabel, this.operationRangeData, 830, 150); this.operationRangeMaxCB.name = "operationRangeMaxCB"; this.operationRangeMaxCB.getTitleLabe().text = this.operationRangeData[0].content; } private CreateComboBox(descLabel: eui.Label, data: any[], positionX: number = 580, boxWidth: number = 400): ComboBox { let y = descLabel.y; let height = descLabel.height; let comboBoxWidth = boxWidth <= 0 ? 400 : boxWidth; let comboBoxX = positionX <= 0 ? 580 : positionX; let cb: ComboBox = new ComboBox(data); this.addChild(cb); //1.点击事宜 cb.addEventListener(ComboBox.onClick, this.onClickComboBoxItem, this); //2.设置title cb.setTitleHeight(height); cb.setTitleBackground("titleBackground_png"); cb.setTitleFontSize(40); //3.设置Item cb.setItemWidth(comboBoxWidth); cb.setItemHeight(height); cb.setItemFontSize(descLabel.size - 1); //4.设置Item内容笔墨的对齐办法 cb.setItemTextAlign("right"); cb.hide(); cb.y = y; cb.x = comboBoxX; return cb; } private onClickComboBoxItem(event) { //getTitleLabe()方法可以获取titleLabel控件。
var titleLabel = event.currentTarget.getTitleLabe(); titleLabel.text = event.target._data.content; event.currentTarget.hide(); }

上述这样写,的确可以在Egret Wing debug的时候成功调用ComboBox,但是,如果发布成为微信小程序,则会报ReferenceError或者gameThirdScriptError。

找到Egret项目的scripts/wxgame/wxgame.ts文件,在对应的位置增加以下代码:

if (filename == "libs/modules/combobox/combobox.js" || filename == 'libs/modules/combobox/combobox.min.js') { content += ";window.ComboBox = ComboBox;"//增加微信小游戏对第三方类库ComboBox的支持 }

大功告成~~~~~~~~~

标签:

相关文章

丰镇市,历史文化与现代发展的交融之地

丰镇市,位于我国内蒙古自治区乌兰察布市中部,是一座历史悠久的城市。自古以来,这里就是兵家必争之地,也是南北文化交流的重要通道。如今...

网站推广 2024-12-23 阅读0 评论0

串行通信协议,构筑现代通信的基石

随着信息技术的飞速发展,通信技术在各个领域都扮演着至关重要的角色。而在众多的通信方式中,串行通信因其高效、可靠的特点,成为了构筑现...

网站推广 2024-12-23 阅读0 评论0

主播推广协议,开启新媒体营销新时代

随着互联网的快速发展,新媒体营销已成为企业品牌推广的重要手段。其中,主播推广以其独特的优势,受到越来越多企业的青睐。在主播推广的过...

网站推广 2024-12-23 阅读0 评论0

主板代码F,介绍计算机心脏的神秘面纱

在科技飞速发展的今天,计算机已经成为了我们生活中不可或缺的一部分。而主板,作为计算机的核心组成部分,承载着整个系统的稳定运行。主板...

网站推广 2024-12-23 阅读0 评论0