Hi there,
I need to implement click and drag (i.e. people click onto an image and drag the image to any place on the screen). I used the method posted on the forum and here’s the JS code. But somehow this doesn’t work with no error message. Could anyone help to see what is not working?
Thanks so much!
if not drag_in_progress and mouse.isPressedIn(img_ball):
drag_in_progress = True
if True in mouse.getPressed():
if drag_in_progress:
mp = mouse.getPos()
if mp[0] <= x_right and mp[0] >= x_left and mp[1] <= y_top and mp[1]>=y_bottom:
img_ball.pos = mouse.getPos()
else:
drag_in_progress = False
if mouse.isPressedIn(submit):
continueRoutine = False
This auto-JS translates to:
var _pj;
function _pj_snippets(container) {
function in_es6(left, right) {
if (((right instanceof Array) || ((typeof right) === "string"))) {
return (right.indexOf(left) > (- 1));
} else {
if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
return right.has(left);
} else {
return (left in right);
}
}
}
container["in_es6"] = in_es6;
return container;
}
_pj = {};
_pj_snippets(_pj);
if (((! drag_in_progress) && mouse.isPressedIn(img_ball))) {
drag_in_progress = true;
}
if (_pj.in_es6(true, mouse.getPressed())) {
if (drag_in_progress) {
mp = mouse.getPos();
if (((((mp[0] <= x_right) && (mp[0] >= x_left)) && (mp[1] <= y_top)) && (mp[1] >= y_bottom))) {
img_ball.pos = mouse.getPos();
}
}
} else {
drag_in_progress = false;
}
if (mouse.isPressedIn(submit)) {
continueRoutine = false;
}