Jump to content

Multi touch - how to get local position for each fingers


CUCHO
 Share

Recommended Posts

Hello everyone.

I am trying to use the touch events in PIXI and I do not know how to get the local position of each finger, I have this:

stage = new PIXI.Container (); // general containerspriteParent = new PIXI.sprite (texture); // for transformsspriteChild = new PIXI.sprite (texture); // for transformsspriteParent.addChild (spriteChild);stage.addChild (spriteParent);stage.touchstart = function (event) { // for two fingers     var point = event.data.getLocalPosition (spriteParent); // this give me the local position for one finger relative to spriteParent coordinates     var finger_1_x = event.data.originalEvent.touches[0].pageX; // these give me the position for two fingers     var finger_1_y = event.data.originalEvent.touches[0].pageY; // but how I get the local position for those?     var finger_2_x = event.data.originalEvent.touches[1].pageX;     var finger_2_y = event.data.originalEvent.touches[1].pageY;     };

Thanks

Link to comment
Share on other sites

Hey!

 

I didn't have time to test, put can you try to pass the touch location in the getLocalPosition ?

var pt = new PIXI.Point(event.data.originalEvent.touches[0].clientX, event.data.originalEvent.touches[0].clientY);var localPt = event.data.getLocalPosition(spriteParent, pt);

If it's not working (probably), you can always create your own touches manager. The touchstart function is called for each touch, so you can store all of them :

var touches = [];stage.touchstart = mousedown();stage.touchend = mouseup();var mousedown = function(event){   var touch = {      id: event.data.identifier,      pos: event.data.getLocalPosition(this.view)   };   touches.push(touch);};var mouseup = function(event){   for (var i = 0; i < touches.length; i++) {      if(touches[i].id === event.data.identifier)      {         touches.splice(i,1);      }   };};

This worked for me :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...