I found an alternative solution this may not automatically allow drag objects to snap to every snap zone but it does allow you to control it with less code.
I created a function to get the object(code) and the zone(outline):
function snapTo(code, outlineSnap) {
var outline = outlines[outlineSnap + '_black'];
if(isNearOutline(code, outline)) {
code.position({
x : outline.x,
y : outline.y
});
console.log("privKey:"+ privKey);
console.log("Key:"+ key);
console.log(code.id());
codeLayer.draw();
var testKey = privKey+ "_black";
if(code.id() == outlineSnap) {
setTimeout(function() {
code.draggable(false);
}, 50);
}
}
}
This function has to be in created the for(var key in codes) {} and outside the drag events. I then called the function inside the dragend event.
code.on('dragend', function() {
snapTo(code, "pstart");
snapTo(code, "pend");
}
There's a bit of an issue with adding the score, I have found a solution that just yet other than keeping the if statement to change draggable to false for the right object outline combination, as if this it taken out the user could 'farm' the drag feature for points...