Hello,
I use a multixy-widget to control parameters whose relative position to each other matters.
I have a multixy-widget with 2 (in the future maybe more) points. My plan is that point 1 acts as the main anchor point, so all other points move relatively to to this point if the anchor is moved. If another point is touched, it should of course not be moved automatically.
I have written the following code for the multixy
onCreate:
var touchedPoints = {}
var pointOffsets = {}
var value = get(this);
for (var i=0; i<getProp(this, 'points'); i++) {
touchedPoints[i] = false;
pointOffsets[i] = [value[2*i] - value[0], value[2*i + 1] - value[1]]
}
setVar(this, 'pointOffsets', pointOffsets)
setVar(this, 'touchedPoints', touchedPoints)
onValue:
var touchedPoints = getVar(this, 'touchedPoints');
var pointOffsets = getVar(this, 'pointOffsets');
if(!touchedPoints[1])
{
value[2] = value[0] + pointOffsets[1][0];
value[3] = value[1] + pointOffsets[1][1];
}
set(this, value);
onTouch:
if (event.handle !== undefined) {
var touchedPoints = getVar(this, 'touchedPoints')
touchedPoints[event.handle] = event.type == 'start' // true or false
setVar(this, 'touchedPoints', touchedPoints)
if(event.handle > 0 && event.type == 'stop'){
var pointOffsets = getVar(this, 'pointOffsets')
pointOffsets[event.handle] = [value[2*event.handle] - value[0], value[2*event.handle + 1] - value[1]]
setVar(this, 'pointOffsets', pointOffsets)
}
}
This kinda works, but the problem is, that the secondary points are only moved on releasing the main point. When instead setting the value of a different multixy it works flawlessly, so this is what i am using as a workaround right now, but i would like to do this with a single multixy.
Has anyone encountered the same problem or knows what i did wrong? is it a racecondition when setting the value of a multixy while also still moving it?