Search code examples
kineticjs

Can I have a switch statement inside kinetic drawFunc? I tried that but failed... I guess NO?


var s= new Kinetic.Shape({ drawFunc: function (c) {
c.beginPath();

c.fillStrokeShape(this); c.stroke()
}, stroke: 'black', fill: 'none', strokeWidth: 1, /*id: tid + '_'+which,*/ visible: show

});


Solution

  • Your code has numerous typos:

    You define loc as a number

    var loc=10;
    

    But read it as a string

    case "left":
    case "right":
    

    Also you have un-terminated quotes on both your case statements.

    It should look more like this:

    var xaxis = 50;
    var loc="left";
    var middle = new Kinetic.Shape({
        drawFunc: function (context) {
            context.beginPath();
            switch(loc){
                case "left":
                    xaxis=10;
                    break;
                case "right":
                    xaxis=20;
                    break;
            }
            context.moveTo(25 + xaxis, 125);
            context.arc(25+xaxis, 135, 10, 1.50*Math.PI, 3.50*Math.PI, false);
            context.fillStrokeShape(this);
            context.stroke()
        },
        stroke: 'black',
        fill: '',
        strokeWidth: 1,
        id: '_middle'
    });