we have been using playcanvas to develop a game and it’s doing well, now that we would like to migrate it to wechat mini-game, but there seems to be some problems, the major one is that wechat mini-game limits the game package to 4M. and my game is 12M…
is there anyway to package less, and load more remotely?
Do you know what is causing the game to be so large? Also, are you permitted to load external resources (eg from another site) with WeChat or does the whole game has to be less than 4M?
yep I know it’s the images and sounds and it should be allowed to load from external resources.
so is there anyway to export scripts and images separately? or do I need to this myself?
For ease, don’t worry about dynamically loading scripts.
You can load images, models, audio dynamically and PlayCanvas does support this but you have to manually handle the assets (when to load it etc).
There’s a few examples on the forums on how dynamically loading external assets.
but in the mean time, we also publishing our game on facebook instant game, which seems forbidden external loading…
so is there anyway to achieve both?
Not from the same project. Unless you create a custom post build processing tool that strips out assets from the build for WeChat and flips a switch to load from an external site.
I’m not sure I completely understand. You need to be clearer about where these limits are applying.
When you create a build from PlayCanvas we include all the runtime assets in your Zip file (whether or not you use them in the game). However, we don’t necessarily load all those assets when the game starts. Use the preload
option on each asset to disable it from being loaded during the preload phase (when the loading bar shows up).
Any asset that is included in your package, but is not set to be preloaded will not be loaded during the preload phase but instead will be loaded
- if it is referenced by an active component
- if it explicitly loaded using
this.app.assets.load(asset)
I don’t believe that FB Instant Games have a limited package size (at least not as low as 20MB). So you can include all your assets in the package and uncheck preload for any assets that you do not need at launch and load them after launch. Like you said, FB doesn’t let you load assets externally (and it’s good for you as they pay the hosting bill).
Is WeChat limiting the package size you can upload to 4MB? But they allow you to host externally? If you need to reduce your package size, make sure that you don’t have runtime assets in your project that are never used in game.
“Is WeChat limiting the package size you can upload to 4MB? But they allow you to host externally?”
exactly, I thinks that’s how it works. the build can not over 4MB, but once in the game, you could load external package. so I guess we need to go @yaustar 's way?
thanks for the clarification!
that seems kind of lot work involved to support build-in assets and remote assets in the same time…
I searched online and find another framework egret do it this way:
while creating a build, one could export some assets in to a separate folder by configuration. and this separate folder could be uploaded to a server.
egret engine have assetmanager that could load the package at runtime.
the article is in Chinese, I could translate it if necessary:
Hmm… It’s not that much work to be honest.
Looking at the files that you get from exporting the build project, I think you can just get away with running a script over the config.json
file to change the urls and hosting the files
folder on another server.
wow, that sounds good, thanks a lot, will work on the script later and update the result
Something like this should work:
- Use asset tags to mark which assets should be in which package.
- After exporting your project, scan the config.json to find assets with the required tag and move them into a different folder.
- Change the URL in the config.json to match the new source URL.
thanks a lot, really helpful hint!