Commit bde6bc89 authored by wjf's avatar wjf

l

parent 69254e50
import Container from "./Container"; import Container from "./Container";
import { RENDERER_TYPE } from "../const" import { RENDERER_TYPE, VERSION } from "../const"
// import SystemRenderer from "../renderers/SystemRenderer"; // import SystemRenderer from "../renderers/SystemRenderer";
import { Rectangle, Point } from "../math"; import { Rectangle, Point } from "../math";
import { EventDispatcher } from "../events/EventDispatcher"; import { EventDispatcher } from "../events/EventDispatcher";
...@@ -131,6 +131,10 @@ export class Stage extends Container { ...@@ -131,6 +131,10 @@ export class Stage extends Container {
private _lastDpList: any = {}; private _lastDpList: any = {};
dpi: number dpi: number
private canvas: HTMLCanvasElement;
private _canvasOffsetX: number = 0;
private _canvasOffsetY: number = 0;
/** /**
* canvas模式下有问题,画布没按style缩小 * canvas模式下有问题,画布没按style缩小
* @param {gl} context * @param {gl} context
...@@ -145,6 +149,7 @@ export class Stage extends Container { ...@@ -145,6 +149,7 @@ export class Stage extends Container {
renderType: RENDERER_TYPE = RENDERER_TYPE.CANVAS, renderType: RENDERER_TYPE = RENDERER_TYPE.CANVAS,
) { ) {
super(); super();
this.canvas = canvas;
let s: Stage = this; let s: Stage = this;
this._instanceType = "Stage"; this._instanceType = "Stage";
Stage._stageList["canvas"] = s; Stage._stageList["canvas"] = s;
...@@ -155,7 +160,18 @@ export class Stage extends Container { ...@@ -155,7 +160,18 @@ export class Stage extends Container {
s.divWidth = divWidth; s.divWidth = divWidth;
s.divHeight = divHeight; s.divHeight = divHeight;
//@ts-ignore淘宝小程序环境下提前记录canvas偏移,到时需要修改id传入,再说把
if (my) my.createSelectorQuery().select('#canvas').boundingClientRect().exec((r) => {
s._canvasOffsetX = r[0].left;
s._canvasOffsetY = r[0].top;
});
// console.log("%c ", "background: url(http://5b0988e595225.cdn.sohucs.com/images/20180315/d41842ad9b5443d3854a480ea49f3b09.gif) no-repeat center;padding-left:80px;padding-bottom: 80px;border-radius:50%;")
//打印个版本号
console.log(
"%c版本:" + VERSION,
// "text-shadow: 0 1px 0 #ccc,0 2px 0 #c9c9c9,0 3px 0 #bbb,0 4px 0 #b9b9b9,0 5px 0 #aaa,0 6px 1px rgba(0,0,0,.1),0 0 5px rgba(0,0,0,.1),0 1px 3px rgba(0,0,0,.3),0 3px 5px rgba(0,0,0,.2),0 5px 10px rgba(0,0,0,.25),0 10px 10px rgba(0,0,0,.2),0 20px 20px rgba(0,0,0,.15);font-size:3em"
)
// my.alert({ // my.alert({
// title: '55729:'+data.canWidth+","+data.canHeight // title: '55729:'+data.canWidth+","+data.canHeight
...@@ -299,6 +315,16 @@ export class Stage extends Container { ...@@ -299,6 +315,16 @@ export class Stage extends Container {
// my.alert({ // my.alert({
// title: '55729:' + points.length // title: '55729:' + points.length
// }); // });
let offSetX = s._canvasOffsetX, offSetY = s._canvasOffsetY;
//@ts-ignore
if (!my) {
let doc = document.documentElement;
let box = s.canvas.getBoundingClientRect();
offSetX = box.left + window.pageXOffset - doc.clientLeft;
offSetY = box.top + window.pageYOffset - doc.clientTop;
}
for (let o = 0; o < points.length; o++) { for (let o = 0; o < points.length; o++) {
if (!points[o]) continue; if (!points[o]) continue;
eLen = 0; eLen = 0;
...@@ -309,8 +335,8 @@ export class Stage extends Container { ...@@ -309,8 +335,8 @@ export class Stage extends Container {
} else { } else {
cp = new Point(); cp = new Point();
} }
cp.x = (points[o].pageX || points[o].x || points[o].b) * s.dpi// devicePixelRatio; cp.x = ((points[o].pageX || points[o].x || points[o].b) - offSetX) * s.dpi// devicePixelRatio;
cp.y = (points[o].pageY || points[o].y || points[o].c) * s.dpi// devicePixelRatio; cp.y = ((points[o].pageY || points[o].y || points[o].c) - offSetY) * s.dpi// devicePixelRatio;
// my.alert({ // my.alert({
// title: JSON.stringify(points[o]) // title: JSON.stringify(points[o])
// }); // });
......
...@@ -186,19 +186,21 @@ export class Lottie extends Container { ...@@ -186,19 +186,21 @@ export class Lottie extends Container {
*/ */
play(loop: number = 0, callback?: () => void) { play(loop: number = 0, callback?: () => void) {
// this.initState(); // this.initState();
this.stop(); this.stop(true);//需要回到初始状态再开始
this.loops = loop; this.loops = loop;
this.callback = callback; this.callback = callback;
this.addTweens(); this.addTweens();
} }
/** /**
* 移除所有的Tween * 移除所有的Tween,临时方法
* @param isReset 是否回到初始状态,默认否
*/ */
stop() { stop(isReset: boolean = false) {
//tween要去掉 //tween要去掉
Tween.removeTweens(this)
this.children.forEach((c) => { Tween.removeTweens(c) }) this.children.forEach((c) => { Tween.removeTweens(c) })
this.initState(); isReset && this.initState();
} }
private addTweens(con = this.children) { private addTweens(con = this.children) {
......
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