Using HTML5 and kineticjs how can i drag a background image even when it is underneath another image or a foreground?
I have setup my own fiddle showing my setup of 2 images here:
The dragging works i just need to be able to drag the darth vader image (background) even when it lies underneath the yoda image (foreground)
I've come across this post on here and example:
Drag while in background in KineticJs
which does exactly what i want just with shapes rather than images using the globalCompositeOperation to draw the background underneath.
My attempt just draws the background above still (see fiddle for full code)
layer.getContext().globalCompositeOperation = "destination-over";
layer.add(background);
stage.add(layer);
Can anyone help?
UPDATE
I now realised what the problem was:
I was creating a new layer each time i added the image therefore the globalCompositeOperation was pointless. I have since moved the new layer out of the image onload function and it now works as expected
Managed to solve moving the layer outside of each image function and adding it to the stage there, followed by layer.draw();
after each image.onload
Working fiddle here: