Drag bug

I have this code:

let current;
covercard.numTouches = 0;
covercard.on("pressdown", function (e) {
current = e.target;
current.numTouches++;
current.copy = makeCard();
current.top();
current.copy.alp(0);
//current.bot();
S.update();
});

    covercard.on("pressup", function (e) {
            current.numTouches--;
            if (current.numTouches > 0) return;
            current = e.currentTarget;
            // swap positions
            swapProperties("x", current, current.copy);
            swapProperties("y", current, current.copy);
            current.copy.alp(1);
            x++;
            graph(current.copy);
            S.update();

    });

it works under ZIM015 but when I change the import to ZIM016 it breaks. The card drags, drops but just freezes there and doesn't create the "grap(current.copy)".

Hi @mathtechie - Jesus, is that you? lol. Fun to say. Make a profile for yourself!!

So can't quite tell what you are working with. Can you edit your question to put the two sets of code in the code format? And what type of object is covercard? Also, is there an error in the console? F12. What code is in graph? Cheers.

The issue may be with this. Using singleTouch on drag() still calls pressup event

You helped me develop this code for a "flashcard" app I built. The issue I was encountering then was with multitouch, if i used two fingers to drag the card instead of one, it would drag the original object and reposition it instead of the copy. It appears the samething is happening again except thist time the copy is not being made as if the "pressup" function is not being recognized. It only happens if i am using two fingers to drag the card. If I use one finger no problem. It's kind of like the issue I had before but different.

Basically, there is a card, covercard (rectangle), on the screen that one drags and it creates a flipper card, "graph()", with stuff on it, various things, graphs, clocks, images, txt boxes, etc., based on the app. This gets created and addded to the "makecard" object, a page object, when the pressup is released. No errors on the console.

This is the code attached to the "covercard", it's a rectangle:

let current;
covercard.numTouches = 0;
covercard.on("pressdown", function(e) {
current = e.target;
current.numTouches++;
current.copy = makeCard();
current.top();
current.copy.alp(0);
//current.bot();
S.update();
});

covercard.on("pressup", function(e) {
current.numTouches--;
if (current.numTouches > 0) return;
current = e.currentTarget;
// swap positions
swapProperties("x", current, current.copy);
swapProperties("y", current, current.copy);
current.copy.alp(1);
x++;
graph(current.copy);
S.update();

});

Okay. Hmmm... I have an idea. Can you make a simple example of the problem without any complicated parts - maybe without a Flipper - not sure if that is needed for this to break. And then post the complete code here with a "this breaks" comment in the code. That way we can figure out how to test this. Thanks! Sorry to be a bother, just still not sure where to start - but good to know it is when dragging with two fingers, etc.

drag the circle with one finger, it makes a copy expected. Use two fingers and it drags but doesn't make a copy and it doesn't return to the center.

Is this the functionality you are hoping for - it works for me now when I drag with more than one finger...

let circle = new Circle(60,red,blue,10)
    .center()
    .drag();

new Label("one").addTo(circle).center();

const start = {x:circle.x, y:circle.y};

let dragCheck = false;
circle.on("mousedown", e=>{
    if (dragCheck) return;
    circle.copy = circle.clone().loc(start).drag().ord(-1);
    dragCheck = true;
});
circle.on("pressup", ()=>{
    dragCheck = false;
    swapProperties("x", circle, circle.copy);
    swapProperties("y", circle, circle.copy);
    S.update();
});

Did you test it with my code? I have dozens of these created with the code in my example and it doesn't work. I reverted back to ZIM 015 for those. Your code works for what I am trying to accomplish but I would have to recode them.

I did test with your code and indeed, it did not work. So you are saying it worked in 015. Sure... we can look into it and see what might have changed and figure out why it breaks now. Just working on some other things - but have set a reminder for the next day or two.

Thanks, Yes, My code worked on ZIM 015. I appreciate it. Thanks,

When singleTouch is not set to true and you drag the same object with a second finger, then which ever finger is moving gets control.

In ZIM 016, we made it so the object only dispatches a pressup for the finger in control and not for the other finger as this was misleading other parts of ZIM to think the pressing was done... when actually the control finger could still be down.

You are adding your own pressdown that increases a count for each finger but you are only getting one pressup and the if test is not letting the rest of the code happen.

If we are stopping a pressup from being dispatched then perhaps we should stop a second pressdown from being dispatched and probably a second pressmove from being dispatched. And make the pressmove only work on the control finger... so it does not bounce back and forth.

Hmmm. I kind of like the second finger being able to take over from the first finger. But then if the first finger is moved, it should not take over from the second finger unless it is lifted and then pressed on the object again. So only the latest finger to press on the object gets control.

I think the second finger should dispatch a mousedown/pressdown so that a clicking sound or something might register. But... should the others, that are no longer in control, dispatch a pressmove and a pressup - I would not think so. Tricky. It is not really being pressed up if the object is no longer underneath it and it is not really being moved if only the other finger is moving it.

Maybe the proper answer is that it should still dispatch the pressup and other things in ZIM should check to see if there is still another cursor on the object before counting it as final pressup. But that is drag, transform, blob, squiggle, gesture, buttons, tabs, dials, sliders, etc. not sure if all use pressup... but... lots of potential places to adjust - mind you, we lasted until ZIM 015 with it like that (primarily because we did not test everything with multitouch in mind).

So... let us think about it.

Also, a reminder to me and others... this is a separate issue from dragging two objects at the same time. This is what we do when we try to drag the same object at the same time with two or more fingers.

1 Like

Thanks for the explanation. I appreciate it.