引言
哈喽大家好,我是亿元程序员,一位有着8年游戏行业经验的主程。
有小伙伴私信笔者:
老师,最近我用AI做了一款微信小游戏,准备上线的时候却发现上传不了,这是为什么呀?
随后发来一张截图:
原来是包体大小超过了限制,这通常需要进行包体优化或者进行分包处理。
言归正传,本期就带大家一起实战看看,Cocos微信小游戏如何进行分包设置。
一.为什么上传不了?
我们一起看看官方文档:
简单解释一下,4M是微信小游戏对游戏“小”的限制,但是随着小游戏的玩法越来越丰富,包大小明显不够用,于是推出了分包加载功能。
再看看小伙伴的项目:
仅仅是主包就已经超过了4M,刚好多了0.2M。
那这应该怎么处理?
二.微信小游戏分包设置
既然官方的解决方案是分包加载,那我们来看看如何进行分包设置(当然在分包之前是对包体资源大小等进行优化,本期不探讨)。
我们先看看Cocos官方文档了解一下:
我们在资源管理器可以看到,resources就是一个AB包(绿色的文件夹上面带个小b)
点击可以在属性检查器里看到相关属性,可以看到有个配置为AB包的选项,但因为resources是内置的,所以无法设置其反选(其他文件夹可以,设置后可以通过代码动态使用资源)。
设置成AB包的目录可以通过下面的方式设置成小游戏的分包。
修改完之后再导出就可以看到一个主包变成了主包+分包,总大小没变:
再次上传就成功了:
那包体大小超过30M的怎么办?
三.通过服务器加载
其实在微信小游戏之前就有这样的方案:
为优化游戏的首次启动时的等待时间,我们可以把运行必要的东西放到首包,其他东西放到后面加载(服务器)。
选择要放到服务器上的文件夹,并且勾选配置为 Bundle:
构建Bundle:
最后通过代码加载即可:
assetManager.loadBundle(
'https://cdn.example.com/game/game1',
(err, bundle) => {
if (err) {
console.error(err);
return;
}
bundle.loadScene('Game', (err, scene) => {
if (!err) {
director.runScene(scene);
}
});
}
);
以上就是Cocos微信小游戏如何进行分包设置的全部内容,如有不对,还请指出。
结语
其实小伙伴已经会用AI开发游戏了,按道理分包问题也可以让AI处理的~
文末还有很多精彩文章推荐,没看过的可以看看哦,感谢支持!
如果你对AI游戏开发也感兴趣,欢迎私信笔者,一起交流,合作,探讨!
我是"亿元程序员",一位有着8年游戏行业经验的主程。在游戏开发中,希望能给到您帮助,也希望通过您能帮助到大家。
PS : 笔者线上的小游戏**《填色之旅》《蚂蚁搬好运》《贪吃蛇掌机经典》《重力迷宫球》《打螺丝闯关》**大家可以自行点击搜索体验。
实不相瞒,想要个赞和爱心!请把该文章分享给你觉得有需要的其他小伙伴。谢谢!
推荐文章:
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
Introduction
Hello, I'm a multi-million dollar programmer. I've had eight years of experience in the game industry.
There's a small partner in the pen:
Teacher, I recently made a little WeChat game with AI, and I couldn't upload it when I was ready to go online.
Then a screenshot was sent:
Originally, the size of the package exceeded the limit, which usually required the optimization of the package or subcontracting.
To put it straight, this time we'll show you how the CocosWeChat game works in subcontracting settings.
Why can't it be uploaded?
Let's look at the official files:
To explain briefly, the 4M is the "small" limit of the WeChat game, but as the game becomes richer, the size of the package is clearly inadequate, so the sub-package is introduced.
And look at the projects of small partners:
It's just the main bag that's over 4M, just better than 0.2M.
What should we do with this?
II. WeChat play subcontracting settings
Since the official solution is subcontracting, let's see how the subcontracting arrangement is made (presumably optimized before subcontracting, for example, the size of the package, which is not explored during this period).
Let's take a look at the official cocos file and find out:
As we can see in the resource manager, the resourcees are an AB package.
Click to see the properties in the attribute checker and see an option to configure to the AB package, but because the resourcees are built-in, it is not possible to set the inverse (other folders can, and then the resources can be used dynamically by code).
The directories set as AB packages can be set into small games subcontracts in the following way.
Once you're done, you can see that the main package becomes the main package + subcontract, and the total size remains unchanged:
It'll work again:
What about the package over 30M?
Loading through the server
This is what happened before the WeChat game:
In order to optimize the waiting time for the first start of the game, we can put what is necessary to run in the first bag and other things on the back load (server).
Select the folder to put on the server and tick the configuration to Bundle:
Build Bundle:
Last thing you can do is load by code:
assetManager.loadBundle(
'https://cdn.example.com/game/game1',
(err, bundle) => {
if (err) {
console.error(err);
return;
}
bundle.loadScene('Game', (err, scene) => {
if (!err) {
director.runScene(scene);
}
});
}
);
This is how the CocosWeChat little game works in the entirety of the subcontracting settings, and if not, please indicate.
Concluding remarks
In fact, the little partner is already using AI to develop the game.
There's a lot of good articles at the end of the book. I can't read them. Thanks for the support.
If you're interested in the development of the AI game, you're welcome as a private penwriter to talk, cooperate, talk!
I'm a "billion dollar programmer" with eight years of experience in the game industry. In the development of the game, you can count on your help.
PS : A little game on the pen line ** "Blowing the ants with good luck" * "The Viper Hand" ** "The Gravity Laceball" ** You can click on the search experience.
I'm telling you, I want a compliment and a love! Please share the article with other young partners you feel need. Thank you!
Recommended articles:
Auto-fetched and translated by AI Atlas. All rights belong to the original author.