1.使用EUI的项目发布到微信小游戏自定义皮肤组件找不到
在所有EUI皮肤类底部追加:
window[“类名”] = 类名;
比如Alert皮肤类 window[“Alert”] = Alert;
2.加载图片跨域限制
设置图片匿名访问
egret.ImageLoader.crossOrigin = “anonymous”;
3.如何压缩类库
打开 /scripts/config.ts
JavaScript
else if (command == 'publish') {
const outputDir = `bin-release/web/${version}`;
return {
outputDir,
commands: [
new CustomPlugin(),
new CompilePlugin({ libraryType: "release", defines: { DEBUG: false, RELEASE: true } }),
new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置
new UglifyPlugin([
{
sources: ["main.js"],
target: "main.min.js"
}
]),
new RenamePlugin({
verbose: true, hash: 'crc32', matchers: [
{ from: "**/*.js", to: "[path][name]_[hash].[ext]" }
]
}),
new ManifestPlugin({ output: "manifest.json" })
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
elseif(command=='publish'){
constoutputDir=`bin-release/web/${version}`;
return{
outputDir,
commands:[
newCustomPlugin(),
newCompilePlugin({libraryType:"release",defines:{DEBUG:false,RELEASE:true}}),
newExmlPlugin('commonjs'),// 非 EUI 项目关闭此设置
newUglifyPlugin([
{
sources:["main.js"],
target:"main.min.js"
}
]),
newRenamePlugin({
verbose:true,hash:'crc32',matchers:[
{from:"**/*.js",to:"[path][name]_[hash].[ext]"}
]
}),
newManifestPlugin({output:"manifest.json"})
]
}
}
修改 UglifyPlugin 插件信息
JavaScript
new UglifyPlugin([
{
// 需要被压缩的文件
sources: [
"libs/modules/egret/egret.min.js",
"libs/modules/egret/egret.web.min.js",
"libs/modules/assetsmanager/assetsmanager.min.js",
"libs/modules/tween/tween.min.js",
"libs/modules/game/game.min.js",
"libs/modules/promise/promise.min.js"
],
// 压缩后的文件
target: "lib.min.js"
},
{
sources: ["main.js"],
target: "main.min.js"
}
])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
newUglifyPlugin([
{
// 需要被压缩的文件
sources:[
"libs/modules/egret/egret.min.js",
"libs/modules/egret/egret.web.min.js",
"libs/modules/assetsmanager/assetsmanager.min.js",
"libs/modules/tween/tween.min.js",
"libs/modules/game/game.min.js",
"libs/modules/promise/promise.min.js"
],
// 压缩后的文件
target:"lib.min.js"
},
{
sources:["main.js"],
target:"main.min.js"
}
])
如果使用了EUI 后面再加上
JavaScript
{
sources: ["resource/default.thm.js"],
target: "default.thm.min.js"
}
1
2
3
4
{
sources:["resource/default.thm.js"],
target:"default.thm.min.js"
}
4.手机震动功能
Java
public static vibrate():void
{
if (navigator.vibrate) {
navigator.vibrate(300);
} else if (navigator["webkitVibrate"]) {
navigator["webkitVibrate"](300);
}
}
1
2
3
4
5
6
7
8
publicstaticvibrate():void
{
if(navigator.vibrate){
navigator.vibrate(300);
}elseif(navigator["webkitVibrate"]){
navigator["webkitVibrate"](300);
}
}
转载声明:本站文章若无特别说明,皆为原创,转载请注明来源:破晓(http://www.code2048.net),谢谢!^^