mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
input: Bug fix: Coordinate calculation of touch events
This commit is contained in:
parent
bdaff72af9
commit
e84f798c7c
@ -115,13 +115,14 @@ func (u *userInterface) FinishRendering() error {
|
||||
func touchEventToTouches(e *js.Object) []touch {
|
||||
scale := currentUI.scale
|
||||
j := e.Get("targetTouches")
|
||||
rect := canvas.Call("getBoundingClientRect")
|
||||
left, top := rect.Get("left").Int(), rect.Get("top").Int()
|
||||
t := make([]touch, j.Get("length").Int())
|
||||
for i := 0; i < len(t); i++ {
|
||||
jj := j.Call("item", i)
|
||||
target := jj.Get("target")
|
||||
t[i].id = jj.Get("identifier").Int()
|
||||
t[i].x = (jj.Get("clientX").Int() - target.Get("left").Int()) / scale
|
||||
t[i].y = (jj.Get("clientY").Int() - target.Get("top").Int()) / scale
|
||||
t[i].x = (jj.Get("clientX").Int() - left) / scale
|
||||
t[i].y = (jj.Get("clientY").Int() - top) / scale
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user