kaboom icon indicating copy to clipboard operation
kaboom copied to clipboard

Position check for touch events "lagging"

Open m3g4p0p opened this issue 4 years ago • 1 comments

Hi,

the position check for touch events is "lagging"; meaning if you add a click listener to an object, the first tap on that object will correctly trigger a click event, however an immediately following tap anywhere else will still trigger a click event on the same object.

Best try it yourself by alternatingly turning off and on "fx" and "music" here (on a mobile device, obviously; the chrome device emulator will do as well though):

import kaboom from 'kaboom'

export const k = kaboom({
  fullscreen: true,
  clearColor: 'black'
})

k.scene('main', () => {
  k.add([
    k.text('fx', 32),
    k.color(1, 1, 1),
    k.pos(0, 0),
    'control'
  ])

  k.add([
    k.text('music', 32),
    k.color(1, 1, 1),
    k.pos(0, 64),
    'control'
  ])

  k.every('control', control => {
    let isActive = false

    control.clicks(() => {
      isActive = !isActive
      control.color = k.rgb(...isActive ? [1, 0, 0] : [1, 1, 1])
    })
  })
})

k.start('main')

Cheers!

m3g4p0p avatar May 22 '21 19:05 m3g4p0p

This might be related: when listening to mouseDown(), for the very first call mousePos() will always return vec2(0, 0):

k.mouseDown(() => {
  // Logs a vec2(0, 0) for the first call,
  // correct results for subsequent calls
  // until mouseRelease()
  console.log(k.mousePos())
})

And after a mouseRelease(), for the next first mouseDown() call the mousePos() will be somewhere near the position from the last mouseDown(), and only then start returning the actual position.

m3g4p0p avatar May 23 '21 11:05 m3g4p0p