Layabox开发微信小游戏好友排行榜功能流程

官方参考文档:(https://ldc2.layabox.com/doc/?nav=zh-ts-5-0-7

一.主域项目,即小游戏(Laya2.0版本)

1. 针对微信小游戏初始化
MiniAdpter.init(true);

2.主域项目中正常创建好友排行榜页面,使用laya2.0新增组件WXOpenDataViewer即可,此处假设定义变量名为openData,如下图所示:

3.在子域项目中使用对应文件之前,需要使用以下接口将加载好的信息透传到子域,(注意:必须要在使用离屏画布之前执行以下操作
Laya.loader.load(["res/atlas/ui/friendsRanking.atlas"], Handler.create(null, function() {
//加载完成
//使用接口将图集透传到子域
MiniAdpter.sendAtlasToOpenDataContext("res/atlas/ui/friendsRanking.atlas");
}));

4.主域中点击排行榜按钮时,显示步骤2中创建的页面,并在页面初始化时通过以下代码传递信息到子域项目,该openData即为步骤2中所定义的变量,postMsg为laya所封装的微信透传方法
// 发送信息到开放域
openData.postMsg({
type: 2, // 该信息可自定义,用于子域中接收信息并判断需要获取哪一类数据,如好友排行榜/群排行
openid: xx, // 主域中透传该参数用于判断自己
});

5.正常打包微信小游戏

二.子域项目,即排行榜所渲染的虚拟屏幕

1. 通过laya2.0.1beta版(大于等于该版本)创建新的开放域项目,如下图所示:

2. 因为在主域项目中透传了一个文件,所以需要在子域中确认该文件已接收才能使用,如下图所示:(注:主域项目和子域项目中需要同时包含所透传的文件,路径一致

3. 正常接收主域透传文件后就可以可初始化排行榜UI了,主要代码为接收主域所传递的信息并获取对应数据(具体代码在开放域项目中有完整demo可以查看)
wx.onMessage(obj)

4.打包该子域项目,注意下图红色框内容是否选定

三.最后的准备

1.在主域项目所打包好的微信小游戏中,修改game.json文件,增加开放域参数,如下代码
"openDataContext": "src/myOpenDataContext",

2.在主域项目所打包好的微信小游戏根目录中,新建文件src/myOpenDataContext/,即步骤1所配置的入口

3.将子域项目所打包出来的文件复制到步骤2的文件夹中,具体如下图所示

注:不需要将所有文件复制过来,只需要复制图中所示文件即可

ok, 愉快的玩耍吧

发布者

Lee

where there is a will, there is a way!

《Layabox开发微信小游戏好友排行榜功能流程》上有6条评论

  1. We offer you the opportunity to advertise your products and services.

    Dear Sir / Madam Please note a fine offering for you. I can send your commercial offers or messages through feedback forms. The advantage of this method is that the messages sent through the feedback forms are included in the white list. This method increases the chance that your message will be read. The same way as you received this message.
    Sending via Feedback Forms to any domain zones of the world. (more than 1000 domain zones.).
    The cost of sending 1 million messages is $ 49 instead of $ 99.
    Domain zone .com – (12 million messages sent) – $399 instead of $699
    All us sites that have a feedback form. (10 million messages sent) – $349 instead of $649
    All domain zones in Europe- (8 million messages sent) – $ 299 instead of $599
    All sites in the world (25 million messages sent) – $499 instead of $999

    Discounts are valid until April 11.
    Feedback and warranty!
    Delivery report!

    In the process of sending messages, we do not violate the rules of GDRP.
    This message is created automatically use our contacts for communication.

    Contact us.
    Telegram – @FeedbackFormEU
    Skype – FeedbackForm2019
    Email – FeedbackForm@make-success.com

    Sorry to bother you.

    This message is created automatically use our contacts for communication.

  2. My name is Pete and I want to share a proven system with you that makes me money while I sleep! This system allows you to TRY the whole thing for F R E E for a whole 30 days! That’s right, you can finally change your future without giving up any sensitive information in advance! I signed up myself just a while ago and I’m already making a nice profit.

    In short, this is probably the BEST THING THAT EVER HAPPENED TO YOU IF YOU TAKE ACTION NOW!!!

    If you’re interested in knowing more about this system, go to http://globalviralmarketing.com/?ref=qkgWOPkN5RoC1NWh and try it out. Again, it’s FREE!

    You can thank me later

    /Pete

  3. Hi,

    I’ve been visiting your website a few times and decided to give you some positive feedback because I find it very useful. Well done.

    I was wondering if you as someone with experience of creating a useful website could help me out with my new site by giving some feedback about what I could improve?

    You can find my site by searching for “casino gorilla” in Google (it’s the gorilla themed online casino comparison).

    I would appreciate if you could check it out quickly and tell me what you think.

    casinogorilla.com

    Thank you for help and I wish you a great week!

发表评论

电子邮件地址不会被公开。 必填项已用*标注