Example

Touch System - with velocities, duration, and release

5

SP4CEBAR 2023-08-08 08:24 (Edited)

This small system can be used to make touchscreen games (like fruit ninja), or GUI features (like scrolling)

The performance impact of this system is below 1% (if you turn the demo off)
The generated variables are all global, and their names have "TOUCH_" as a prefix, with the exception of "G_DELTA_TIME" which is a constant equal to 1/60

the touch system generates:

and some other variables are generated along the way:

This function is called on every loop:

SUB TOUCH_MANAGER
  IF TOUCH THEN
    IF TAP THEN 
      TOUCH_TIMESTAMP = TIMER
      TOUCH_INITIAL_X = TOUCH.X
      TOUCH_INITIAL_Y = TOUCH.Y
    END IF

    TOUCH_VX = (TOUCH.X - TOUCH_PREVIOUS_X) * G_DELTA_TIME
    TOUCH_VY = (TOUCH.Y - TOUCH_PREVIOUS_Y) * G_DELTA_TIME
    TOUCH_PREVIOUS_X = TOUCH.X
    TOUCH_PREVIOUS_Y = TOUCH.Y
    TOUCH_DURATION   = TIMER - TOUCH_TIMESTAMP
    TOUCH_RELATIVE_X = TOUCH.X - TOUCH_INITIAL_X
    TOUCH_RELATIVE_Y = TOUCH.Y - TOUCH_INITIAL_Y
  END IF
  RELEASE  = (TOUCH_PREVIOUS<>TOUCH) AND NOT TOUCH
  TOUCH_PREVIOUS   = TOUCH
END SUB

Touch System.nx | Open in app
2023-08-08 08:24

was8bit 2023-08-08 11:36

Most impressive :)


SP4CEBAR 2023-08-09 16:55

Thank you!


Log in to reply.