Commit 021e347f authored by wjf's avatar wjf

l

parent dc936b45
...@@ -3,6 +3,8 @@ node_modules ...@@ -3,6 +3,8 @@ node_modules
/src /src
/build/svgaPlayer.min.js.map /build/svgaPlayer.min.js.map
tsConfig.json tsConfig.json
package-lock.json
webpack.config.js webpack.config.js
/.vscode /.vscode
/scripts /scripts
\ No newline at end of file record.txt
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
兼容web和淘宝小程序的svga文件播放器 1.0.3版本 兼容web和淘宝小程序的svga文件播放器 1.0.3版本
仅web轻量解析 1.0.4版本 仅web轻量解析 1.0.4版本 1.0.6版本(支持换图)
### 网页使用 ### 网页使用
......
...@@ -162,6 +162,12 @@ export class MovieClip extends EventDispatcher { ...@@ -162,6 +162,12 @@ export class MovieClip extends EventDispatcher {
* @since 1.0.0 * @since 1.0.0
*/ */
stop(): void; stop(): void;
/**
*
* @param imagekey 对应的imagekey
* @param imageUrl 图片路径,以后考虑支持多种形式
*/
setImage(imagekey: string, imageUrl: string):void
/** /**
* 将播放头向后移一帧并停在下一帧,如果本身在最后一帧则不做任何反应 * 将播放头向后移一帧并停在下一帧,如果本身在最后一帧则不做任何反应
* @method nextFrame * @method nextFrame
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
{ {
"name": "@mrkwon/svga-player", "name": "@mrkwon/svga-player",
"version": "1.0.4", "version": "1.0.6",
"description": "", "description": "",
"main": "build/svgaPlayer.min.js", "main": "build/svgaPlayer.min.js",
"types": "build/SvgaPlayer.d.ts", "types": "build/SvgaPlayer.d.ts",
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import { EventDispatcher, Event } from "./EventDispatcher"; import { EventDispatcher, Event } from "./EventDispatcher";
import { _bitmapCache } from "./SvgaStage";
/** /**
* 动画类 * 动画类
...@@ -223,6 +224,18 @@ export class MovieClip extends EventDispatcher { ...@@ -223,6 +224,18 @@ export class MovieClip extends EventDispatcher {
} }
} }
/**
*
* @param imagekey 对应的imagekey
* @param imageUrl 图片路径,以后考虑支持多种形式
*/
setImage(imagekey: string, imageUrl: string) {
if (!this.videoItem.images[imagekey]) return;
//从缓存去掉
_bitmapCache[imagekey] = 0;
//修改数据
this.videoItem.images[imagekey] = imageUrl;
}
/** /**
* 调用止方法将停止当前帧 * 调用止方法将停止当前帧
......
...@@ -33,7 +33,7 @@ export class SvgaStage extends EventDispatcher { ...@@ -33,7 +33,7 @@ export class SvgaStage extends EventDispatcher {
this.children = []; this.children = [];
//计算canvas尺寸和动画显示尺寸之间的比例,暂时只有缩放 //计算canvas尺寸和动画显示尺寸之间的比例,暂时只有缩放
this.resolution = resolution; this.resolution = resolution;
this.requestAnimationFrame = canvas.requestAnimationFrame&&canvas.requestAnimationFrame.bind(canvas)||window.requestAnimationFrame.bind(window) this.requestAnimationFrame = canvas.requestAnimationFrame && canvas.requestAnimationFrame.bind(canvas) || window.requestAnimationFrame.bind(window)
//直接刷吧 //直接刷吧
// this.flush(); // this.flush();
} }
...@@ -108,14 +108,16 @@ export class SvgaStage extends EventDispatcher { ...@@ -108,14 +108,16 @@ export class SvgaStage extends EventDispatcher {
//加载 //加载
if (!_bitmapCache[imageKey]) { if (!_bitmapCache[imageKey]) {
let src = child.videoItem.images[imageKey]; let src = child.videoItem.images[imageKey];
let imgTag = this.canvas.createImage && this.canvas.createImage() || new Image();
imgTag.onload = function () {
_bitmapCache[imageKey] = imgTag;
};
if (src.indexOf("iVBO") === 0 || src.indexOf("/9j/2w") === 0) { if (src.indexOf("iVBO") === 0 || src.indexOf("/9j/2w") === 0) {
let imgTag = this.canvas.createImage && this.canvas.createImage() || new Image();
imgTag.onload = function () {
_bitmapCache[imageKey] = imgTag;
};
imgTag.src = 'data:image/png;base64,' + src; imgTag.src = 'data:image/png;base64,' + src;
_bitmapCache[imageKey] = 1;//表示在加载中 } else {
imgTag.src = src;
} }
_bitmapCache[imageKey] = 1;//表示在加载中
} }
//绘制 //绘制
else { else {
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
var svgaStage = new SvgaPlayer.SvgaStage(canvas) var svgaStage = new SvgaPlayer.SvgaStage(canvas)
//加载动画数据 //加载动画数据
SvgaPlayer.loadSvga("./angel.svga", function (videoItem) { SvgaPlayer.loadSvga("./angel.svga", function (videoItem) {
console.log(videoItem)
//实例化动画 //实例化动画
var mv = new SvgaPlayer.MovieClip(videoItem); var mv = new SvgaPlayer.MovieClip(videoItem);
//添加进动画容器 //添加进动画容器
...@@ -29,6 +31,7 @@ ...@@ -29,6 +31,7 @@
mv.startAniRange(1, mv.totalFrames / 2, 2, () => { mv.startAniRange(1, mv.totalFrames / 2, 2, () => {
console.log(112) console.log(112)
}) })
mv.setImage("GuangHuan","https://cdn2.jianshu.io/assets/default_avatar/6-fd30f34c8641f6f32f5494df5d6b8f3c.jpg")
}, 2000) }, 2000)
// mv.rotation = 45 // mv.rotation = 45
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment