All Projects → dotgreg → Weixin Minigame Tutorial

dotgreg / Weixin Minigame Tutorial

Flappy Bird adaptation on Wechat Minigame using PhaserJS + English Wechat Minigames Tutorial

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Weixin Minigame Tutorial

Mina Webpack
🍱 Mina single-file-component meets Webpack
Stars: ✭ 77 (+37.5%)
Mutual labels:  wechat-mini-program, wechat, weixin
Taro
开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
Stars: ✭ 30,230 (+53882.14%)
Mutual labels:  wechat-mini-program, wechat, weixin
Agora Miniapp Tutorial
Hello world for Agora SDK running in https://en.wikipedia.org/wiki/WeChat#WeChat_Mini_Program
Stars: ✭ 75 (+33.93%)
Mutual labels:  wechat-mini-program, wechat, weixin
Tina
💃 一款轻巧的渐进式微信小程序框架
Stars: ✭ 1,153 (+1958.93%)
Mutual labels:  wechat-mini-program, wechat, weixin
Planmaster
套餐助手:手机套餐对比选购小程序
Stars: ✭ 487 (+769.64%)
Mutual labels:  wechat-mini-program, wechat, weixin
Crmeb wechatminiprogram
CRMEBv2.6以客户管理为中心+电商营销系统,微信小程序商城,带分销、秒杀、积分、优惠券等功能
Stars: ✭ 158 (+182.14%)
Mutual labels:  wechat-mini-program, wechat, weixin
Taro scaffold
基于 Taro / dva / redux-saga / react 的微信小程序脚手架,同时集成了 sprite 。
Stars: ✭ 24 (-57.14%)
Mutual labels:  wechat-mini-program, wechat, weixin
Juejin
💰 Unofficial JueJin wechat mini program application - 掘金非官方微信小程序
Stars: ✭ 771 (+1276.79%)
Mutual labels:  wechat-mini-program, wechat, weixin
Wepy Mall
微信小程序--基于wepy 商城(微店)微信小程序 欢迎学习交流
Stars: ✭ 3,224 (+5657.14%)
Mutual labels:  wechat-mini-program, wechat, weixin
Wxapp Webpack Plugin
📦 微信小程序 webpack 插件
Stars: ✭ 185 (+230.36%)
Mutual labels:  wechat-mini-program, wechat, weixin
Quietweather
☀️ Develop a weather wechat mini program application in two days - 两天撸一个天气应用微信小程序
Stars: ✭ 677 (+1108.93%)
Mutual labels:  wechat-mini-program, wechat, weixin
Weixin Java Miniapp Demo
基于Spring Boot 和 WxJava 实现的微信小程序Java后端Demo
Stars: ✭ 779 (+1291.07%)
Mutual labels:  wechat-mini-program, wechat, weixin
Xiaochengxu demos
小程序优秀项目源码汇总,每个项目都有图有源码,零基础学微信小程序,小程序表格,小程序视频,小程序视频弹幕,小程序仿天猫大转盘抽奖等源码,小程序云开发,小程序发邮件,小程序支付,微信支付,持续更新。。。
Stars: ✭ 855 (+1426.79%)
Mutual labels:  wechat, weixin
Weixinmpsdk
微信全平台 SDK Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 6.0。已支持微信公众号、小程序、小游戏、企业号、企业微信、开放平台、微信支付、JSSDK、微信周边等全平台。 WeChat SDK for C#.
Stars: ✭ 7,098 (+12575%)
Mutual labels:  wechat, weixin
Weixin Pay
微信支付
Stars: ✭ 863 (+1441.07%)
Mutual labels:  wechat, weixin
Weixin Sdk
微信公众平台和微信支付Python-SDK
Stars: ✭ 20 (-64.29%)
Mutual labels:  wechat, weixin
Weixin Platform History Article Api
微信公众号历史文章爬取api
Stars: ✭ 27 (-51.79%)
Mutual labels:  wechat, weixin
Ios Chat
开源的即时通讯(野火IM)系统
Stars: ✭ 867 (+1448.21%)
Mutual labels:  wechat, weixin
Teleball
Build your own Arduino based retro handheld game console
Stars: ✭ 21 (-62.5%)
Mutual labels:  game, tutorial
Node Tenpay
微信支付 for nodejs
Stars: ✭ 947 (+1591.07%)
Mutual labels:  wechat, weixin

Preview

Introduction

This repository contains

  • a phaser-minigame template, ready to use
  • a fully functional minigame demo of Flappy Bird on Phaser
  • an Wechat Minigame guide

The current demo includes the following functionalities:

  • A fully working integration of phaser 2.9 + pixiJs + p5 gravity engine (source: littlee/wechat-small-game-phaser);
  • An ES6-based scalable code structure (based on import/export features);
  • Game functionalities used:
    • Animated Sprite based on JSON;
    • Import and Caching assets system;
    • Animations;
    • A Gravity system;
    • A Collision system;
    • A Social leaderboard system based on Leancloud;

Code Structure

├───game.js : main entry point, Phaser. Game main function declared here
├───game.json : minigame configuration
├───images : static assets repository
└───js
    ├───game
    │   ├───managers : each manager is a set of functions
    │   │   ├───collisions.js : handles all collision events 
    │   │   ├───db.js : backend CRUD functions for leaderboard (based on Leancloud API)
    │   │   ├───events.js : main events of the game functions
    │   │   ├───generators.js : objects generators functions
    │   │   ├───leaderboard.js : functions that handle leaderboard and ranking algorithms
    │   │   ├───wechat.js : functions that handle WeChat-related API (getting user profile, user friends list etc...)
    │   └───objects : Each object is a Class, with its separated file
    │       ├───Background
    │       ├───Bird
    │       ├───Button
    │       ├───Floor
    │       ├───Pipe
    │       ├───objects.js : singleton namespace window.objects where all the game objects live
    │       ├───phases.js : different game phases (preload, create, update (called every frame), render (called every frame))
    │       └───state.js : singleton namespace window.state where all the game states and parameters live
    └───libs
        └───lodash-modules

Minigame Guide

  1. How do WeChat minigames work?
  2. Can I already code my own minigame? When will it be released?
  3. What are the limitations? What are the acceptable expectations in terms of performance?
  4. Are Web → Minigame and Minigame → Web conversions possible?
  5. Getting started
  6. IDE & Debugging tools presentation
  7. Making your Minigame Social: available APIs
  8. Resources and links to get started
  9. Some advice before you start

1) How do WeChat minigames work?

Overall Architecture : Almost like web games

Wechat Minigames are based on web technologies, the main language used is Javascript. The system is similar to the one on the web: a canvas element is accessible and we can draw on it at every frame. We have access to the WebGL API, and thus able to use the GPU for calculations using Shaders (GLSL language).

ctx.fillRect(25, 25, 100, 100);
ctx.clearRect(45, 45, 60, 60);
ctx.strokeRect(50, 50, 50, 50);

But implementation has some differences

However, the WebGL and Canvas API implementation differ from the native web implementation you can find on most web browsers. The running environment of the minigame is JavaScriptCore on iOS, and V8 on Android. All of them are running environments without both BOM and DOM. There is no global document ad no window object. So, if you want to use the DOM API to create elements like Canvas and Image, it will throw an error. More on Official Minigame documentation (Chinese).

Web Libraries can get adapted to the Minigame environment

To bridge the gap between web and minigame, the WeChat minigame team has been working on a special library, weapp-adapter. The goal is to make web libraries compatible with Minigames. The current implementation of the library, however, is still imperfect and incomplete, and extra work it’s often needed to fix each third-party library you intend to work with.

Many web gaming engines have already been ported (Officially and unofficially)

Engine Focus Status
Cocoa Chinese 2d UI-based Web Game engine Officially supported
Laya Chinese 2d & 3d Web Game engine Officially supported
Egret Chinese 2d UI-based Web Game engine Officially supported
Unity 3D/2D Game engine, industry standard Not supported yet
Phaser (Web) 2D Web Game engine, industry standard in web gaming Working through unofficial port
Threejs 3D Web engine, industry standard Working through unofficial port

2) Can I already code my own minigame ? When will it be released?

Can I already code my own minigame? Yes, you can already code your own minigame! Everything you will need, from documentation to developer tools, are publicly available.

Can it be released yet? No, it can’t be published yet, but you can still preview it on your phone. (More on IDE presentation following)

When will it be released? We don’t know yet.

3) What are the limitations? What are the acceptable expectations in terms of performance?

Games graphics styles: both 2D and 3D are possible.

Thanks to the access to WebGL, we can also display 3D games, which will be GPU accelerated.

Performance: A slightly better-optimized system than Web games

The system is still young and in beta-testing phase, but we can already see that performance is very similar to what web games are capable of. A good rule of thumb, for the moment, is not to expect more than what a web game can do, in terms of limitations.

Size is still the main constraint.

One of the biggest limitations of a minigame is coming from its size. Wechat currently allows only up to 4MB-packages games. Your game will probably be able to download extra assets from an external server, but take into account that those will have to be fetched for every time the game is started. So, games should be rather light in terms of assets, and 3D games should use low-poly 3D objects and low quality textures.

4) is Web game→ WeChat Minigame conversion possible? What about WeChat Minigame → Web game conversion?

Web → Minigame conversion: depends heavily upon the underlying codebase

It is possible to convert web games to minigames. However, according to the specific libraries and game engine used, the process could take from days to months of development. Prior audit of the game source code is required to estimate how much time the particular adaptation will take.

Minigame → Web conversion: it’s fast!

If using a standard web gaming framework for minigame development, like Phaser, your code will mostly be already web compatible, so it will work on a browser without much tweaking.

5) Getting Started with an Official Minigame Example

  1. Download Wechat Miniapp&Minigame IDE
  2. Follow the steps to get the Tencent sample code up and running.

  1. You can now preview the sample minigame on your phone by clicking on the Eye button and scanning the QRcode.

6) IDE & Debugging tools presentation

The IDE and debugging tools are the same as mini-apps. Those are, however, purely in Chinese. The debugging experience is overall very good, although it might be somewhat buggy due to its youth.

The whole interface has been translated into English here, for clarity.

7) Making your Minigame Social: available WeChat APIs

One of the core points of interest of minigames is the seamless access to social features embedded inside the WeChat platform, which increase their vitality and engagement rates. Here is a presentation of the main mechanisms and how to use them.

Get current User information

wx.login({
  success: function () {
    wx.getUserInfo(userInfos)
  }
})

Other personal information you can get:

wx.getLocation() => user location
wx.getWeRunData() => get podometer data from werun 

https://mp.weixin.qq.com/debug/wxagame/dev/tutorial/open-ability/authorize.html?t=201832

Get Friends-who-played-the-game data list

wx.getFriendCloudStorage()
  • Gets the data for each user from the user’s friend list;
  • Those data can be modified and written on;
  • Good for friend leader board, and in-game friend status indications;

Get Group-who-played-the-game data list

wx.getGroupCloudStorage()
  • Gets the data from each user within a group where the minigame has been shared;
  • Those data can be modified and written on;
  • Good for group-based game;

8) Resources and links to get started

Mini Games

Phaser Game Library

9) Some advice before you start

Don’t trust the preview, always test on real devices.

This is an example of a piece of code working on an emulator, but not on a real device:

  static preload(game) {
    game.load.image('bg', 'js/game/objects/Background/bg.jpg') => working on both emulator + phone
    // game.load.image('bg', './js/game/objects/Background/bg.jpg') => working only on emulator
  }

Limit usage of third-party Libraries, as extra work is often needed

Libraries like lodash are not working out of the box. You often need to go into the source code and modify the part depending on DOM/BOM APIs to actually achieving loading them. On Lodash, you could solve the problem by adding the specific modules one by one, and not the whole library in one go. But it’s not always so easy!

npm install --save lodash.forEach
NOT
npm install --save lodash

Chunk your code in smaller files to make debugging easier

The current IDE debugging system is working differently from their counterparts on Chrome and Firefox. One of the biggest sources of frustration I have encountered, is that many problems will end up throwing a very vague, non-specific error message, without any information on where the problem is coming from, except for the file it is failing onto. Dividing your code in smaller chunks is therefore very important, as finding a typo in a thousand lines worth of file, without a single hint, is much more difficult than finding a typo on a 50-lines file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].