Question

J'utilise jCanvas pour peindre sur un élément canvas HTML. D'abord, j'initialiser un x * x table, chaque cellule tenant une toile:

function init(size) {
            // Adding the board table to the body
            $("#content").append("<table class=\"board\">");

            for(i=0; i<size; i++) {
                $(".board").append("<tr>")
                for(j=0; j<size ; j++) {
                    $(".board tr:last-child").append("<td class=\"square\">");
                }
            }
            // Setting size to match width or height, whichever i smallest
            var h = $("#content").height();
            var w = $("#content").width();
            var rez = (w > h) ? h : w;
            var cSize = rez / size;
            $(".board td").append("<canvas width="+cSize+" height="+cSize+" />");
            $(".board").css("width",rez);
            $(".board").css("height",rez);

            // Drawing icons on the board
            var c = $("canvas");
            var icns = new Array(11);
            for(i=0; i<11; i++)
                icns[i] = "svg/"+ params["hvor"] +"/"+ (i+1) +".svg";

            for(i=0; i<c.length; i++) {
                var rand = Math.floor(Math.random()*(icns.length-1));
                var icn = icns[rand];
                icns.splice($.inArray(icns[rand], icns), 1);
                $(c[i]).drawImage({
                    source: icn,
                    height: cSize,
                    fromCenter: false
                });
            }
        }

Cela fonctionne bien, et les images est dessiné sur la toile. J'essaie alors d'ajouter une couche avec une nouvelle forme (il doit être retiré plus tard, c'est pourquoi j'utilise une couche).

$('td').click(function(){
    var h = $(this).height() -2;
var o = h / 3.5;
var t = h / 10;

$(this).children("canvas").addLayer({
    method: "drawLine",
    strokeStyle: "#5cfe15",
    strokeWidth: t,
    x1: o, y1: o*2,
    x2: h/2, y2: h-o,
    x3: o*3, y3: o-t
});
});

C'est quand je reçois le Uncaught TypeError: Object [object Object] has no method 'addLayer' d'erreur. il tire en fait, si je viens d'utiliser drawLine() au lieu de addLayer() la ligne, de sorte que l'objet est clairement une toile.

Qu'est-ce que je manque ici?

Était-ce utile?

La solution

Assurez-vous que vous utilisez v5.0 jCanvas, car il introduit la méthode addLayer () pour les collections jQuery (qui est, .fn $).

-Caleb

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top