gpt4 book ai didi

fabricjs - Fabric.js 颜色在子类 fabric.Group 中变为黑色

转载 作者:行者123 更新时间:2023-12-05 07:46:56 28 4
gpt4 key购买 nike

我正在尝试子类化 fabric.Group 并将 JSON 字符串加载到其中。我遇到的问题是 fabric.Rect 子类组中的颜色正在变为黑色。当我直接在 fabric.Group 中进行时,效果很好。我一直在玩 fromObject 的变体,但我似乎无法弄清楚我做错了什么。当我“活跃”组中的对象时,这种变化似乎发生了。

这是一个演示我的问题的 fiddle https://jsfiddle.net/adgu/49feomm7/
单击“加载组”按钮可以看到红色矩形(这是正确的),单击“加载自定义组”按钮可以看到黑色矩形。除了在一种情况下类型为“group”而在另一种情况下为“customGroup”之外,JSON 是相同的。

fabric.CustomGroup = fabric.util.createClass(fabric.Group, {

type: 'customGroup',

initialize: function(objects, options) {
options || (options = { });
//console.log('initialize objects', objects);
//console.log('initialize options', options);
this.callSuper('initialize', objects, options);
},

toObject: function() {
return fabric.util.object.extend(this.callSuper('toObject'), {
});
},

_render: function(ctx) {
this.callSuper('_render', ctx);
}
});

fabric.CustomGroup.fromObject = function(object, callback) {
//console.log('fromObject', object);
var _enlivenedObjects;
fabric.util.enlivenObjects(object.objects, function (enlivenedObjects) {
//console.log('enlivenObjects object', object);
//console.log('enlivenObjects object.objects', object.objects);
//console.log('enlivenObjects enlivenedObjects', enlivenedObjects);
delete object.objects;
_enlivenedObjects = enlivenedObjects;
});
return new fabric.CustomGroup(_enlivenedObjects, object);
};

最佳答案

我找到了解决我的问题的已关闭错误报告:https://github.com/kangax/fabric.js/issues/3156

通过将 true 添加到初始化 callSuper 的末尾,它开始工作。像这样:

this.callSuper('initialize', objects, options, true);

关于fabricjs - Fabric.js 颜色在子类 fabric.Group 中变为黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40391668/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com