在看LampStripLightSmear的的源码的时候发现有一个@ray-js/pencil-flow库,我在已经这个库写canvas的时候给每个图形添加事件无效,无法实现像LampStripLightSmear一样给每个图像添加事件, 只要滑动一次就无法打印log了,无法触发事件了
Code: Select all
addIdxShapeIns(idx, _data) {
// 防止重复生成相同的shape
if (this[idx]) {
return this[idx];
}
const preDataKey = `preData_${idx}`;
const preData = this[preDataKey];
let shape = null;
if (preData) {
const isEqualObj = isEqual(preData, _data);
if (!isEqualObj) {
shape = new Round(_data);
this[preDataKey] = _data;
}
} else {
shape = new Round(_data);
this[preDataKey] = _data;
}
if (!shape) {
return;
}
this[idx] = shape;
// 添加事件
shape.on(TRIGGER_EVENT_MOVE, this.shapeTouchMove);
shape.on(TRIGGER_EVENT_END, this.shapeTouchEnd);
this.stage.add(shape); // 渲染 canvas
},
shapeTouchEnd(e) {
console.log('shapeTouchEnd', e);
const value = e.target.data;
this.touchend(value.idx);
},
shapeTouchMove(e) {
console.log('shapeTouchMove', e);
const value = e.target.data;
this.touchmove(value.idx);
},