0

KineticJSを使用して、2 つの形状の交差のみを表示したい。これどうやってするの?以下のリンクのようにしてみました。 HTML5 キャンバス クリッピング領域。他に方法はありますか?

4

2 に答える 2

1

globalCompositeOperationこれを行うには、http://jsfiddle.net/wbzwX/を使用できます。

ctx.fillStyle="#000";
ctx.fillRect(50,50,100,100);

ctx.globalCompositeOperation = "source-in"; 
// this will use the fillstyle of the next drawn object. 
// "destination-in" will use the previous fillstyle.

ctx.beginPath();
ctx.arc(100,50,30,0,Math.PI*2,false);
ctx.closePath();
ctx.fillStyle="#f00";
ctx.fill();​
于 2012-12-07T18:51:48.777 に答える
0

Shmiに基づいてソリューションを作成しました。

   function makeShapeComposite(shape, operation) {
        shape.attrs._drawFunc = shape.attrs.drawFunc;
        shape.attrs.drawFunc = function (context) {
            context.save();
            context.globalCompositeOperation = operation;
            this.attrs._drawFunc.call(this, context);
            context.restore();
        };
        return shape;
    };   

   var pol=  makeShapeComposite(new Kinetic.RegularPolygon({
           x: 250,
            y: 100,
            sides: 4,
            radius: 70,
            fill: '#00D2FF',
            stroke: 'black',
            strokeWidth: 2
        }), "destination-in");

フィドル: http://jsfiddle.net/sara9/2v7W2/5/

このチュートリアルを参照してください。

于 2012-12-09T05:29:27.300 に答える