Проверил - всё работает
И выложил свой плагин в дискорде discord.com/channels/883781994583056384/1178765569487556748
Вот переписанный вариант управления:
export default function swipeComp() {
let left
let right
let up
return {
id: "swipeComp",
require: [],
direction: vec2(0),
move: false,
isAction: false,
action: false,
add() {
right = this.add([
pos(width() / 2, height()),
rect(width() / 2, height()/2),
opacity(0),
fixed(),
area(),
anchor("botleft"),
multitouch(),
])
left = this.add([
pos(0,height()),
rect(width() / 2, height()/2),
opacity(0),
fixed(),
area(),
anchor("botleft"),
multitouch(),
])
up = this.add([
pos(),
rect(width(), height()/2),
opacity(0),
fixed(),
area(),
multitouch(),
])
onResize(() => {
left.pos = vec2(0,height())
left.width = width() / 2
left.height = height() / 2
right.pos = vec2(width() / 2, height())
right.width = width() / 2
right.height = height() / 2
up.pos = vec2(0)
up.width = width()
up.height = height() / 2
})
up.onPointUpdate(() => {
if (this.isAction) return
this.direction.y = -1
})
right.onPoint(() => {
if (this.isAction) return
this.direction.x = 1
this.parent.trigger("startMove")
})
left.onPoint(() => {
if (this.isAction) return
this.direction.x = -1
this.parent.trigger("startMove")
})
right.onPointUpdate(() => {
if (this.isAction) return
this.direction.x += 0.1
})
left.onPointUpdate(() => {
if (this.isAction) return
this.direction.x -= 0.1
})
this.onPointUpdate(() => {
this.parent.trigger("input", this.direction.unit())
})
this.onPointEnd((num) => {
if (num <= 1) {
this.parent.trigger("endMove")
this.direction = vec2(0)
}
})
let lastTouchPos = null
this.onTouchStart(() => {
lastTouchPos = mousePos()
})
this.onTouchMove(() => {
this.isAction = true
if (mousePos().dist(lastTouchPos) > 10) {
this.parent.trigger("action")
if (!this.action) {
this.parent.trigger("startAction")
this.action = true
}
this.direction = mousePos().sub(lastTouchPos).unit()
}
lastTouchPos = mousePos()
})
this.onTouchEnd(() => {
lastTouchPos = null
this.direction = vec2(0)
this.move = false
this.action = false
this.isAction = false
})
}
}
}Предыдущий вариант тут можете сравнить