npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lottie-pixi

v0.0.5

Published

render lottie animation with pixi

Downloads

30

Readme

lottie-pixi

一个高性能的解析和播放 lottie 动画的工具包,动画渲染基于 [email protected] 引擎。

What it is

lottie-pixi 是一个为 pixi.js 引擎准备的动画工具集,可以无缝的帮助你在 pixi.js 技术体系上扩展 lottie 动画basic 动画.

Why use it

lottie-pixi 被设计用来解决重型、复杂的多动画场景,如果你遇到了以下问题,那么 lottie-pixi 将是你最好的解决方案。

  • 你需要在一个canvas中播放多个lottie 动画
  • 你的lottie 动画需要动态替换一些内容
  • 你需要给lottie 动画中的某个图片加点击事件
  • 你在开发一个小游戏,需要用到动画lottie 动画
  • 你的lottie 动画遇到性能问题

哪些情况下不建议使用 lottie-pixi

  • 动画非常简单,lottie-web 就已经够用了的时候
  • 会创建非常多canvas的时候,例如:列表中的每个按钮都是一个lottie 动画,创建过多的webgl会有性能问题
  • 页面中最多不要同时存在多个webgl上下文,这在移动端会有系统限制

Features

  • lottie 动画:支持 lottie 动画特性,功能、图层效果对标 lottie-canvas
  • 绝对性能优势:借助 pixi 强大的 Sprite 和 shape 合并渲染,在大量渲染对象场景下性能优势明显
  • overlap 模式:在 lottie 之上创造性的新增 overlap mode,在实际场景中非常有用
  • 动画插槽功能:支持动画插槽功能,你可以轻松的在动画中添加 你自己的渲染节点 或 新lottie动画节点
  • 高自由度:你可以完全掌控动画中的每一个渲染对象
  • basic 动画:支持 transform-alpha 属性插值动画,包括 tween 动画 和 bodymovin 动画

Install

npm install -S lottie-pixi

Usage

Lottie 动画

你只需调用一个函数就能播放动画,非常方便。

import 'lottie-pixi/build/pixi'; // pixi v5.x 的组装代码
import { loadAnimation } from 'lottie-pixi';

const animation = loadAnimation({
  view: '#load-animation',
  path: 'http://image.uc.cn/s/uae/g/01/lottieperformance/webglcanvas/game-preview/data.json',
});

或者创建一个 AnimationManager 单例来解析和管理任意多个 lottie 动画文件。并将它们添加到渲染引擎的任意渲染节点上。

import 'lottie-pixi/build/pixi'; // pixi v5.x 的组装代码
import { Application } from '@pixi/app'; // pixi v5 import
import { AnimationManager } from 'lottie-pixi';

const app = new Application({
  view: document.getElementById('demo-canvas'),
  width: window.innerWidth,
  height: window.innerHeight,
});

// just need single instance with one app
const animationManager = new AnimationManager(app);

// parse one or more anims
const anim1 = animationManager.parseAnimation({
  keyframes: data1,
});
const anim2 = animationManager.parseAnimation({
  keyframes: data2,
});

app.stage.addChild(anim1.group, anim2.group);

Basic 动画

lottie 动画 适合处理多物体的复杂运动,而 basic 动画 主要适用于单个物体运动的场景,假如你只想要某个物体做个小动画,basic 动画 就是最好的选择。

你可以直接在任意显示对象上调用 animatebodymovin 方法触发一个动画。

import 'lottie-pixi/build/pixi'; // pixi v5.x 的组装代码
import { Application } from '@pixi/app'; // pixi v5 import
import { Graphics } from '@pixi/graphics'; // pixi v5 import
import { EnableAnimations, Tween } from 'lottie-pixi';

const app = new Application({
  view: document.getElementById('demo-canvas'),
  width: window.innerWidth,
  height: window.innerHeight,
});

const ball = new Graphics();
ball.beginFill(0xFFFFFF, 1);
ball.drawCircle(250, 250, 50);
ball.endFill();

// 播放 from-to 动画
const anim = ball.animate({
  from: {x: 100},
  to: {x: 200},
  ease: Tween.Bounce.Out,
  // ... 更多配置
});

// 或者 播放 bodymovin 动画
const anim = ball.bodymovin({
  keyframes: data.layers[3], // 指定使用 lottie 动画数据的某一个图层的关键帧
  frameRate: data.fr,
  ignoreProps: [ 'position', 'scaleX' ], // 忽略某些属性
  // ... 更多配置
});

app.stage.addChild(ball);