GithubHelp home page GithubHelp logo

effects-miniprogram-demo's Introduction

Galacean Effects 微信小程序 Demo

使用步骤

1、安装依赖

# 安装 Galacean Effects 的小程序/小游戏适配器
$ npm i @galacean/appx-adapter --save
# 安装 Galacean Effects
$ npm i @galacean/effects --save

2、在小程序中使用

<view style="width: 375px; height: 375px; background-color: black">
  <canvas type="webgl" id="J-webglCanvas" style="width: 100%; height: 100%;"></canvas>
</view>
import { registerCanvas } from '@galacean/appx-adapter/weapp';
import { Player } from '@galacean/effects/weapp';

// 1. 使用 adapter 方法注册 canvas
const canvas = await registerCanvas({ id: '#J-webglCanvas' });
// 2. 通过创建的 canvas 对象实例化一个 Galacean Effects 播放器
const player = new Player({
  transparentBackground: true,
  canvas,
  pixelRatio: 2,
  renderFramework: 'webgl',
});

// 3. 加载资源并执行播放
void this.player.loadScene('url');

注意:

  • Galacean Effects 对小程序的适配包使用了 package.json exports,NodeJS v12.7.0 和 Typescript v4.7 及以上才支持,同时 tsconfig.jsonmodule 需配置为 ESxxx(如:ESNext)。

基于原生 js/ts 模版的小程序

  1. 直接下载并使用编译好的 js 库(即本仓库下的:libs/mp-weapp-galacean-effects.js
  2. 放到自己的项目中,并在业务代码中引入并使用:
import { adapter, Player } from '../../libs/mp-weapp-galacean-effects';

// 同上面的示例代码,不同是 registerCanvas 要从 adapter 命名空间下获取
const canvas = await adapter.registerCanvas({ id: '#J-webglCanvas' });

完整示例代码见本仓库的 resources 目录。

开发

本地开发

开始开发

# 1. 安装依赖(首次)
npm install
# 2. 构建小程序产物
npm run build

Tips

  • npm run build 会把 miniprogram/pages 下的 .ts 编译成 .js,然后通过微信开发者工具即可编译或预览

effects-miniprogram-demo's People

Contributors

yiiqii avatar

Stargazers

question avatar  avatar 飂兮 avatar 诸葛思清 avatar Walter Cheng avatar  avatar

Watchers

ChenMo avatar  avatar Hu Song avatar  avatar

effects-miniprogram-demo's Issues

Error: plugin 'spine' not found.

import { registerCanvas } from "@galacean/appx-adapter/weapp";
import {
 Player,
 AbstractPlugin,
 registerPlugin,
} from "@galacean/effects/weapp";

import "@galacean/effects-plugin-spine";

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.