Skip to content

@leafer-game/miniapp ​

Based on @leafer-ui/miniapp, this package introduces plugins including Robot, interaction state, animation, motion path, and element search, making it suitable for game scenarios.

​

web version     worker version     node version     mini program version ​

​

Runs in a mini program environment. Learn about npm usage considerations in mini programs.

Installation ​

sh
npm install @leafer-game/miniapp
sh
pnpm add @leafer-game/miniapp
sh
yarn add @leafer-game/miniapp
sh
bun add @leafer-game/miniapp

Update ​

Learn how to quickly update versions.

Download CDN version ​

You can also download the library file locally and import it directly. This method currently cannot use additional plugins.

sh
https://unpkg.com/@leafer-game/miniapp@2.3.1/dist/miniapp.module.js

https://unpkg.com/@leafer-game/miniapp@2.3.1/dist/miniapp.module.min.js

Notes ​

  1. WeChat Mini Program has issues loading SVG images.
  2. Shadows and some features are still being adapted for compatibility.
  3. When used in the web-view component, WeChat JS-SDK uploads PNG images as JPG format. Please use native HTML5 input for uploading.

Try it ​

Create an interactive engine that supports landscape mode and allows dragging rectangles.

Replace the page under miniprogram/pages/index with the following content:

ts
import { Leafer, Rect } from '@leafer-game/miniapp'

Page({
  onReady() {
    // this refers to the current mini program page instance
    const leafer = new Leafer({ view: 'leafer', eventer: this })

    const rect = new Rect({
      x: 100,
      y: 100,
      width: 100,
      height: 100,
      fill: '#32cd79',
      draggable: true,
    })

    leafer.add(rect)
  },
  receiveEvent() {}, // predefined method for receiving interaction events
})
xml
<canvas

    type="2d"
    catchtouchstart="receiveEvent"
    catchtouchmove="receiveEvent"
    catchtouchend="receiveEvent"
    catchtouchcancel="receiveEvent"
></canvas>
css
page {
  height: 100%;
}
#leafer {
  width: 100%;
  height: 100%;
}
json
{
  "navigationStyle": "custom",
  "pageOrientation": "auto"
}

Usage ​

The usage, global variables, and @leafer-ui/miniapp are consistent. You only need to change the package name to run the official example code.

Released under the MIT License.