简体   繁体   中英

kineticjs group cache and layer draw is hiding kinetic arc shapes

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM