Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically created HTML5 canvas element in Kinetic.js fails with draggable:true
    primarykey
    data
    text
    <p>I've been playing around with KineticJS and I've run into an interesting problem. I'm not really sure how to solve it. Here is my code.</p> <p>HTML </p> <pre><code>&lt;body&gt; &lt;div id="container"&gt;&lt;/div&gt; &lt;script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.2.min.js"&gt;&lt;/script&gt; &lt;/body&gt; </code></pre> <p>JavaScript</p> <pre><code>// Kinetic Example var stage = new Kinetic.Stage({ container: 'container', width: 578, height: 400 }); var layer = new Kinetic.Layer(); var circle = new Kinetic.Circle({ x: stage.getWidth() / 2, y: stage.getHeight() / 2, radius: 70, fill: 'red', stroke: 'black', strokeWidth: 4, draggable: true }); // add the shape to the layer layer.add(circle); // add the layer to the stage stage.add(layer); // My doCircle function function doCircle(ddata) { var layer = new Kinetic.Layer(); var circle = new Kinetic.Circle({ x: ddata[1], y: ddata[2], radius: ddata[3], fill: '' + ddata[4] + '', stroke: '' + ddata[5] + '', strokeWidth: ddata[6], draggable: true }); layer.add(circle); stage.add(layer); } // Data example (will be from user input) var data = "circle 50 50 20 green blue 5"; // Make data an array var arrData = data.split(" "); // Get draw type switch (arrData[0]) { case "circle": doCircle(arrData); break; } </code></pre> <p>I've also made a <a href="http://jsfiddle.net/TJcyY/" rel="nofollow">JS Fiddle </a> for this. You'll notice the the large red circle statically made is draggable. The smaller green circle that I built using "data" when clicked, either disappears or sets to 0,0 on the canvas. I'm assuming this is possibly a data type issue with data<a href="http://jsfiddle.net/TJcyY/" rel="nofollow">1</a> and data[2] from the array on the x,y of the circle? But if that were the case why does the element render correctly in the first place and only break when attempted to drag it?</p> <p>Thanks for your help and solutions. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload