tutorial broken using 4.3.1
The excellent tutorial shown below no longer works using Kinetic 4.3.1:
http://www.html5canvastutorials.com/labs/html5-canvas-drag-and-drop-resize-and-invert-images
Moving an anchor does not resize the image as expected. Instead, the anchor becomes disassociated from the image. Moving around different anchors occasionally results in correct behavior, but only for a time.
Understanding that the API has changed, it would be very helpful if this tutorial could be updated to give some idea of what is required to update to 4.3.1 (unless this is a bug?).
Eric
Thanks for letting us know. How about this tutorial with similar functionality -
http://tech.joshuacummings.com/2012/07/scalable-draggable-anchored-triangle-in.html
I'll probably be testing this later this week in 4.3.1, but if you have any insight on whether it needs to be updated for the new build (and how), do let us know. Thanks!
Nevin
Sorry, Nevin, I don't have any specific insight: my shape-resizing code is modeled after the broken tutorial and, of course, is now broken in 4.3.1. My fear (not insight) is that the new use of a temporary top layer for drag/drop has broken the connection between the moving anchor and the rest of the shapes in the group, but it's not based on any data ....
I could not get the v3.10.0 tutorial you mentioned to work in my local file:// environment using kinetic 4.1.2 or kinetic 4.3.1. I'm not sure why, but only a single horizontal line is displayed. Anyway, I do notice that "your" tutorial puts the anchors in one layer and the triangle in another, while "my" tutorial groups the anchors and the primary shape into a single group in one layer, so that the whole group can be displayed, removed, etc. in one operation. So if you can get "your" tutorial to work but not "mine", the separation of anchors and primary shape might be a clue.
Eric
Thanks for letting me know. I'm going to try getting this to work shortly and perhaps try having everything in one layer. And I'm not sure this relates to either of our tutorials, but half the time I've found that the problem is that I neglect to call layer.draw() at the appropriate time, so that might be something else to watch out for with this (or other) scripts.
Nevin
Okay, I got the triangle working in 4.3.1 -
http://webdev.edtechleaders.org/classroom_applet/triangle_test.html
I surmise you could get the polygon image to work by adding an additional point, and then using the fillPatternImage attribute as in this JSFiddle -
http://jsfiddle.net/LNeML/12/
Hope that helps!
N.
Yes, I see that your triangle_test.html does work. But it is significantly different from the tutorial I pointed out at:
http://www.html5canvastutorials.com/labs/html5-canvas-drag-and-drop-resize-and-invert-images
All of the anchors and the triangle in triangle_test are separate shapes on a layer, while the broken tutorial above puts the anchors and primary shape (or image) into a group.
Note that the fiddle you created does contain anchors at all and therefore is not relevant to the current problem, so far as I can see. I was not saying the image won't move, but rather that it does not resize as the anchors move.
It seems to me that the original question is still open: what changes must be made to the original (group-enabled) tutorial to get it to work? As I said, this might not be a bug, just a change in API or a change in proper technique. So I'm not sure how to proceed: it might be worthwhile modifying your triangle_test to put the anchors and triangle in a group, or it might be simpler to fix the original tutorial. Do you need me to check whether the triangle_test works with groups before you look at the original tutorial?
Eric
Hmmm, very good points. In my view, I think it would be best to work with the existing tutorial and revise it, since most of the time when I have migrated from an early kineticjs version to the current one, it has just been about changing the syntax. For instance, have needed to swap in new lines of code for gradient fills, getting objects (using stage.get instead of this.get), and how I remove layers. I have also noticed that as far as I've seen you cannot have groups within groups in 4.3.0 and up, though I'm not sure if that's relevant to this tutorial.
I'm actually finishing a project for work and don't necessarily have time to work on the image tutorial now, but if I have time later in the week, I'll see if I can tackle it! My approach would be to just add the code to a new file and have it pull in 4.3.1 from the beginning - then I'd just keep tweaking the code until I get it to work. Apologies for not being able to do more at the moment, but I hope that helps.
Nevin
OK, thanks, I'll await your further investigations using the yoda tutorial page. For when you get back to it ... I see now that the bottomRight anchor works fine (resizes the image), but the other three are broken.
using stage.get instead of this.get
Also, the yoda code calls group.get(), not stage.get(), so if an API change was made (I don't see it in the changelog) that could be a problem.
Thanks for helping,
Eric
I experienced the same problems in my resize code based on that tutorial. The tutorial is failing because the circle being dragged is not a member of the group when the update method is called. One of the group.get calls is returning undefined. I believe the "missing" circle is in the new drag layer when update is called.
A quick fix is to add a line to each switch case in update. case "topLeft": topLeft = activeAnchor; .... case "topRight": topRight = activeAnchor; ....
Good catch, your fix may be pointing to the root of the problem ... since it implies that this code does not work:
var topLeft = group.get(".topLeft")[0];
var topRight = group.get(".topRight")[0];
... which either is a bug or a change to the API that we don't understand. Hopefully, an expert will weigh in.
Eric
You guys are correct. I finally had a chance to look at the lab, and there is indeed a problem with this scenario:
appears to be a problem with .get() when trying to select children of the parent of a node that is being dragged and dropped, with dragOnTop = true. See drag and drop with resize lab
The quickest work around for the lab is to set dragOnTop = false for the anchors. I've updated the lab and it's working again. I'll address the problem with get() by the next release.
Thanks guys!
Thanks, Eric, this fix works for me -- but only if I set dragOnTop to false for each shape in a group, not just the anchors. Otherwise, only some components of the group move, leaving others behind. If there is a way to turn off dragOnTop globally, please let me know: better to have a one-line fix than to change all of the many groups that I create. (Note that setting dragOnTop to false at the group level did not work -- each component had to be set).
Eric
Fixed - the dynamic drag layer now does a deep copy for the Groups and Layers that are reconstructed (which means they now also pick up ids and names and should play well with selectors). The change will be available with the 4.3.2 release this week. Thanks!