kineticjs group cache and layer draw is hiding kinetic arc shapes

試著忘記壹切 提交于 2019-12-12 02:52:20

问题


I am creating a circle as a group of kinetic arcs. When I cache the group and subsequently call the draw function on the layer, three quarters of the circle are hidden. I think layer.draw may require an offset but really I'm only guessing. When I remove the fill, stroke or opacity from the arc or the object literal from the cache call then the full circle is displayed. http://jsfiddle.net/leydar/gm2FT/5/ Any insights gratefully received.

function createArc(n){
    var arc = new Kinetic.Arc({
        innerRadius: 30,
        outerRadius: 50,
        /* if I remove the fill, stroke or opacity 
           the full wheel is correctly displayed */
        fill: 'blue',
        stroke: 'black',
        opacity: 0.3,
        strokeWidth: 1,
        angle: 36,
        rotation: 36*n
    });

    return arc;
}

function init() {
var arc;

    var stage = new Kinetic.Stage({
        container: 'container',
        width: 104,
        height: 104
    });

    var layer = new Kinetic.Layer();
    var circle = new Kinetic.Group();

    for(var i=0;i<10;i++) {
        arc = createArc(i);
        circle.add(arc);
    };

    layer.add(circle);
    stage.add(layer);

    /* if I do not cache or do not call layer.draw()
       then again the wheel is correctly displayed */
    circle.cache({
        x: -52,
        y: -52,
        width: 104,
        height: 104,
        drawBorder: true
    });
    layer.draw();
}

init();

Stephen


回答1:


This is a bug of KineticJS. You may use this workaround:

Kinetic.Arc.prototype._useBufferCanvas = function() {
    return false;
};

http://jsfiddle.net/gm2FT/6/



来源:https://stackoverflow.com/questions/24069175/kineticjs-group-cache-and-layer-draw-is-hiding-kinetic-arc-shapes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!