Touch screen - dragging gesture

Hi I have got a complex situation here. I would like my screen to not register any finger-dragging gesture on a touch screen, because it messes up my program.

My opening lines are:
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3(0, 0, 0);
var camera = new BABYLON.UniversalCamera(“UniversalCamera”, new BABYLON.Vector3(0, 0, -10), scene);
var touch = new BABYLON.FreeCameraInputsManager();
camera.inputs = touch;
camera.attachControl(canvas, false);

As you can see, I already try to disable using mouse to adjust the camera. And later in the game, I have things that catch the appropriate gesture:

          mesh.actionManager = new BABYLON.ActionManager(scene);
          mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickDownTrigger, pushkey));
          mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickUpTrigger, releasekey));
          mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickOutTrigger, releasekey));
          mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOutTrigger, releasekey));

However, whenever I make a “dragging” gesture on the touch screen, the whole game messes up. Is there a way to bypass that? In other words, I would only want the screen to react when I tap and release specify objects and make sounds accordingly.


1 Like

Instead of attaching the camera to the canvas, attach the scene only. This way events are still triggered, but the camera won’t react to them

Fantastic. It’s getting better as I did what you recommended. Thanks!
If I have two or more fingers on the touch screen…all moving or not independently, how can I get an “array” of pointers info in real time. For example, pointer 1 at x,y…pointer 2 at x,y… etc


So, the PointerEvent interface has a pointerId parameter (a number), with which you can check what pointer is currently touching the screen. We provide a pointer event if you register to this observable:

Due to JS’s single-threaded behavior, they will never execute “ath the same time” but one after the other (with no guaranty for order), so you will need to take care of assembling the fingers together :slight_smile:

You are being so helpful! Thank you!!!

Is there a function that easily checks when there is no pointer at the moment? i.e. all the pointers have “lifted”

I have read this doc countless of times but I can’t find a place to check if no pointers actions are at the moment. The story is this:

If you try it on a touch screen, some notes are stuck (un-released) even though the pointer was out (or no more pointers at touching the screen). So I thought to run the code periodically to clean up these stuck keys.