I am making an application in which user can drag & drop multiple objects from a toolbar onto a canvas.After dragging and dropping that particular object onto the canvas the user can move that object around in the canvas.Double Clicking on that object will make it disappear.I have been able to implement this for one object in the toolbar as shown in the link below..
To drag & drop multiple objects from the toolbar I made the following additions in the function DragDrop()
var image2 = new Kinetic.Image({
name: data,
id: "image"+(imageCount++),
x: x,
y: y,
image2: theImage2,
draggable: true
});
image2.on('dblclick', function() {
image2.remove();
layer.draw();
});
layer.add(image2);
layer.draw();
var image3 = new Kinetic.Image({
name: data,
id: "image"+(imageCount++),
x: x,
y: y,
image3: theImage3,
draggable: true
});
image3.on('dblclick', function() {
image3.remove();
layer.draw();
});
layer.add(image3);
layer.draw();
The Fiddle containing the above code is http://jsfiddle.net/gkefk/29/
Even though I've made the necessary additions in the DragDrop() function, the two new objects are visible in the toolbar but i'm not being able to drag,drop,move around and delete them like the first object.Please Help...
I made it work with some major changes:
The image sources are provided in a dynamic array - so you can extend this at one single place in your code:
(of course you also have to update your HTML with the toolbar accordingly)
The list of images gets processed in a loop and for each element a new draggable object is created in connection with the corresponding
<img id = "..." />
:The counter for IDs is only relevant to the new element that is created on drop. As you only drop one image at the same time you also have to create a single
new Image()
only, instead of trying to create three of them.Your working example can be found here and is extensible: http://jsfiddle.net/gkefk/32/