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

svga-egret

v1.0.4

Published

预览svga动画网址 http://svga.io/svga-preview.html

Downloads

32

Readme

SVGAPlayer-egret

预览svga动画网址 http://svga.io/svga-preview.html

修改自原github项目 https://github.com/yyued/SVGAPlayer-Web

专门为egret使用svga动画的扩展类EgretMovieClip

npm使用

npm install svga-egret
import {Parser,EgretMovieClip}from "svga-egret"

网页使用 注意得在白鹭的js后加下面脚本(因为继承了egret.DisplayObjectContainer)

<script src="libs/svga.egret.min.js"></script>

代码示例

var parser = new SVGA.Parser();
parser.load("../egret/loading五神兽最终版.svga", (videoItem) => {
    //具体用法SVGA.d.ts文件有
    var mv = new SVGA.EgretMovieClip(videoItem)
    // mv.lockStep=true;
    // mv.play()
    // mv.gotoAndPlay(30, true)
    // mv.gotoAndStop(10)
    // mv.startAniRange
    mv.gotoAndPlay(1, true)
    this.addChild(mv);
    let fun
    mv.addEventListener(egret.Event.COMPLETE, fun = function () {
            console.log("播放完成")
            // mv.removeEventListener(egret.Event.COMPLETE,fun,this)
            // mv.stop()
            // mv.startAniRange(30,60);
        }, this)
    }, function (error) {
     alert(error.message);
})

使用指南(原生形式使用)

原生canvas形式使用,

手动加载

添加 <script src="https://cdn.jsdelivr.net/npm/[email protected]/build/svga.min.js"></script> 到 your.html 页面

你可以自行创建 Player 和 Parser 并加载动画

  1. 添加 Div 容器
<div id="demoCanvas" style="styles..."></div>
  1. 加载动画
var player = new SVGA.Player('#demoCanvas');
var parser = new SVGA.Parser('#demoCanvas'); // 如果你需要支持 IE6+,那么必须把同样的选择器传给 Parser。
parser.load('rose_2.0.0.svga', function(videoItem) {
    player.setVideoItem(videoItem);
    player.startAnimation();
})

自动加载

为 canvas 元素添加以下属性

<div src="rose_2.0.0.svga" loops="0" clearsAfterStop="true" style="styles..."></div>

动画会在页面加载完成后播放

动态图像

你可以动态替换动画中的指定元素,询问你的动画设计师以获取 ImageKey。

  • 用于替换的图片,宽、高必须与原图一致。
  • setImage 操作必须在 startAnimation 之前执行。
player.setImage('http://yourserver.com/xxx.png', 'ImageKey');

动态文本

你可以在指定元素上添加文本,询问你的动画设计师以获取 ImageKey。

  • setText 操作必须在 startAnimation 之前执行。
player.setText('Hello, World!', 'ImageKey');
player.setText({ 
    text: 'Hello, World!, 
    size: "24px", 
    color: "#ffe0a4",
    offset: {x: 0.0, y: 0.0}
}, 'ImageKey'); // 可自定义文本样式

Classes

SVGA.Player

SVGA.Player 用于控制动画的播放和停止

Properties

  • int loops; - 动画循环次数,默认值为 0,表示无限循环。
  • BOOL clearsAfterStop; - 默认值为 true,表示当动画结束时,清空画布。
  • string fillMode; - 默认值为 Forward,可选值 Forward / Backward,当 clearsAfterStop 为 false 时,Forward 表示动画会在结束后停留在最后一帧,Backward 则会在动画结束后停留在第一帧。

Methods

  • constructor (canvas); - 传入 #id 或者 CanvasHTMLElement 至第一个参数
  • startAnimation(reverse: boolean = false); - 从第 0 帧开始播放动画
  • startAnimationWithRange(range: {location: number, length: number}, reverse: boolean = false); - 播放 [location, location+length] 指定区间帧动画
  • pauseAnimation(); - 暂停在当前帧
  • stopAnimation(); - 停止播放动画,如果 clearsAfterStop === true,将会清空画布
  • setContentMode(mode: "ScaleToFill" | "AspectFill" | "AspectFit"); - 设置动画的拉伸模式
  • setClipsToBounds(clipsToBounds: boolean); - 如果超出盒子边界,将会进行裁剪
  • clear(); - 强制清空画布
  • stepToFrame(frame: int, andPlay: Boolean); - 跳到指定帧,如果 andPlay === true,则在指定帧开始播放动画
  • stepToPercentage(percentage: float, andPlay: Boolean); - 跳到指定百分比,如果 andPlay === true,则在指定百分比开始播放动画
  • setImage(image: string, forKey: string, transform: [a, b, c, d, tx, ty]); - 设定动态图像, transform 是可选的, transform 用于变换替换图片
  • setText(text: string | {text: string, font: string, size: string, color: string, offset: {x: float, y: float}}, forKey: string); - 设定动态文本
  • clearDynamicObjects(); - 清空所有动态图像和文本

Callback Method

  • onFinished(callback: () => void): void; - 动画停止播放时回调
  • onFrame(callback: (frame: number): void): void; - 动画播放至某帧后回调
  • onPercentage(callback: (percentage: number): void): void; - 动画播放至某进度后回调

SVGA.Parser

SVGA.Parser 用于加载远端或 Base64 动画,并转换成 VideoItem。

跨域的 SVGA 资源需要使用 CORS 协议才能加载成功。

如果你需要加载 Base64 资源,或者 File 资源,这样传递就可以了 load(File)load('data:svga/2.0;base64,xxxxxx')

Methods

  • constructor();
  • load(url: string, success: (videoItem: VideoEntity) => void, failure: (error: Error) => void): void;

Issues

Android 4.x 加载失败

某些 Android 4.x OS 上缺少 Blob 支持,请自行添加 Polyfill。

<script src="//cdn.bootcss.com/blob-polyfill/1.0.20150320/Blob.min.js"></script>

支持 SVGA-Format 1.x 格式

如果你需要播放 1.x 格式的 SVGA 文件,需要添加 JSZip 到你的 HTML 页面中。

<script src="//s1.yy.com/ued_web_static/lib/jszip/3.1.4/??jszip.min.js,jszip-utils.min.js" charset="utf-8"></script>