Laya的微信小游戏,开放域项目

发布微信小游戏项目

创建项目时,勾选微信/百度小游戏bin目录快速调试

发布项目时,选择发布平台为微信小游戏

用微信开发者工具打开release/wxgame,这就是微信小游戏项目了,很方便

总结:

白鹭发布微信小游戏和Laya发布微信小游戏差不多

 4M包限制与动态资源

由于有4m包限制,所以一般小游戏项目分成主包+远程资源。

现在我新建一个remote目录,该目录下资源不发布到微信小游戏目录下,而是服务器远程加载。

发布时,勾线是否提取本地包

远程资源目录remote不需要勾选

这是发布出的项目有两个文件夹,其中wxgame是常规项目,wxgame_pack是不含remote文件夹的项目

可以看到wxgame_pack确实是不含有remote文件夹的

 那么我们微信提交时,只需要提交主包wxgame_pack就行了。将remote资源放到服务器动态加载。

平时我们使用remote的图片是这样的。加载remote.atlas图集,并显示其中test1.jpg

Laya.loader.load("res/atlas/remote.atlas", Laya.Handler.create(this, ()=>{
     let sp:Laya.Sprite = new Laya.Sprite();
     sp.texture = Laya.loader.getRes("remote/test1.jpg");
     this.addChild(sp);
}));

  

现在资源放在远程服务器了。加载地址就变成了http://xxxxx/res/atlas/remote.atlas,该地址根据你的实际服务器地址决定。

Laya.loader.load("http://127.0.0.1:8011/wxgame/res/atlas/remote.atlas", Laya.Handler.create(this, ()=>{
    let sp:Laya.Sprite = new Laya.Sprite();
    sp.texture = Laya.loader.getRes("remote/test1.jpg");
    this.addChild(sp);
}));

  

Laya论坛有个方法。就是设置Url.basePath。这样load的每个路径都会自动加上basePath。,而MiniAdpter.nativefiles白名单里的资源,只会从本地加载。

但是实际测试没卵用。这个白名单并不会生效。查看源码bin/libs/laya.core.js,ctrl+F搜索class loader找到加载类,发现并没有地方使用了nativefiles这个白名单。

Laya.URL.basePath = "http://127.0.0.1:8011/wxgame/";

Laya["MiniAdpter"].nativefiles = [
      "wxlocal",
      "res/atlas/comp.atlas"
]

总结:

白鹭发布本地和远程资源,分成两个资源文件,本地default.res.json和远程remote.res.json,本地资源不会加前缀,远程资源会加上http://xxxxx.com/前缀。这样就可以解决这个问题本地和远程包问题。

Laya发布本地和远程资源,则暂时没发现什么好的方法。

猜你喜欢

转载自www.cnblogs.com/gamedaybyday/p/11512155.html