Impossibile aggiungere il livello alla tela usando jcanvas
Domanda
Sto usando jcanvas per dipingere su un html canvas
elemento. Innanzitutto inizialisco la tabella AX * X, con ogni cella che tiene una tela:
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
});
}
}
Funziona bene e le immagini vengono disegnate sulla tela. Provo quindi ad aggiungere un livello con una nuova forma (deve essere rimosso in seguito, ecco perché sto usando un livello).
$('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
});
});
È allora che ricevo l'errore Uncaught TypeError: Object [object Object] has no method 'addLayer'
. Se uso solo drawLine()
invece di addLayer()
In realtà trae la linea, quindi l'oggetto è chiaramente una tela.
Cosa mi manca qui?
Soluzione
Assicurati di utilizzare JCanvas v5.0, poiché ha introdotto il metodo AddLayer () per le raccolte jQuery (cioè $ .fn).
-Caleb
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow