Nate
thank you for your reply
Based on your answer, my code is written like this.
input.addListener({
down: (x, y) => {
startX = x;
startY = y;
mouse.set(x, canvas_1.clientHeight - y, 0)
var bestDistance = 20,
index = 0;
var best;
for (var i = 0; i < controlbones.length; i++) {
hoverTargets[i] = null;
let bone = skeleton.findBone(controlbones[i]);
var position = new spine.Vector2(bone.length, 0);
bone.localToWorld(position);
let distance = renderer.camera.worldToScreen(
coords.set(bone.worldX, bone.worldY, 0),
canvas_1.clientWidth, canvas_1.clientHeight).distance(mouse);
// let distance = Math.sqrt((coords.x - bone.x) * (coords.x - bone.x) + (coords.y - bone.y) * (coords.y - bone.y));
if (distance < bestDistance) {
bestDistance = distance;
best = bone;
index = i;
}
}
if (best) hoverTargets[index] = best;
target = best;
},
up: (x, y) => {
target = null;
dragging = false;
},
dragged: (x, y) => {
currentX = x;
currentY = y;
const distanceX = currentX - startX;
const distanceY = currentY - startY;
if(!dragging && (Math.abs(distanceX) > 5 || Math.abs(distanceY) > 5)){
dragging = true;
startX = x;
startY = y;
}
// hair_distance = Math.sqrt(distanceX ** 2 + distanceY ** 2);
if (dragging) {
dragged(canvas_1, renderer, target, x, y);
}
}
})
function dragged(canvas_1, renderer, target, x, y){
if (target) {
x = spine.MathUtils.clamp(x, 0, canvas_1.clientWidth);
y = spine.MathUtils.clamp(y, 0, canvas_1.clientHeight);
dragX = x;
dragY = y;
var newX = startX + 0.20*(dragX - startX);
var newY = startY + 0.20*(dragY - startY);
renderer.camera.screenToWorld(coords.set(newX, newY, 0), canvas_1.clientWidth, canvas_1.clientHeight);
if (target.parent !== null) {
target.parent.worldToLocal(position.set(coords.x, coords.y));
target.x = position.x;
target.y = position.y;
} else {
target.x = coords.x;
target.y = coords.y;
}
}
}
I wonder if this is a problem of the skeleton rather than a problem of touch.
This is because the same phenomenon occurs when the skeleton is moved by clicking with the mouse as well as by touching.
When the skeleton is pulled to the place where the hair is, it comes down to the outside and then goes up again.
When the skeleton is moved to the outside where there is no hair, the skeleton is naturally moved, but when the skeleton is moved to the inside where there is hair, the phenomenon of moving outside and then moving is still present.