I have to set a max clone number that limits cloning items. Those items are draggable. The problem will be described in this example:
Code:
cloneImg.on('dragend', function(){
if (img.maxClones>0)
{
img.maxClones--;
var point = cloneImg.getPosition();
rightLayer.draw(this);
stage.draw();
}
else {
alert("Equipment Unavailable: max number is "+max+", and has already been reached.");
revert(this,this.startX,this.startY);
rightLayer.draw();
stage.draw();
}
}
I should add a line or two after an event, but can't seem to localize it. What do I do to prevent this from happening?
Maybe rework your logic to start with an appropriate stack of clones on top of the original:
A Demo: http://jsfiddle.net/m1erickson/3XSAz/
On the startup screen:
On clone dragend
If you want to get fancy you could make the non-draggable original at 50% opacity so the user can visually see when they have used all the available elements.
Example code:
var sw=stage.width();
var sh=stage.height();
layer.add(new Kinetic.Rect({x:sw/2,y:0,width:sw/2,height:sh,fill:"lightblue"}));
var original = new Kinetic.Circle({
x:100,
y:100,
radius: 30,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
opacity:0.50,
});
original.maxClones=2;
layer.add(original);
layer.draw();
makeClones(original);
function makeClones(base){
for(var i=0;i<original.maxClones;i++){
var clone=base.clone({draggable:true,opacity:1.00});
clone.startingX=clone.x();
clone.startingY=clone.y();
clone.on("dragend",function(){
if(this.x()>sw/2){return;}
this.x(this.startingX);
this.y(this.startingY);
layer.draw();
});
layer.add(clone);
}
layer.draw();
}