0

I try to move a circle to mouseposition on an ipad with this code:

    function CircleMovetoMouse(){
         var mousePos = stage.getMousePosition();
         var xpos = mousePos.x;
         var ypos = mousePos.y ;

          var circle1 = stage.get('#Circle1')[0];
           new Kinetic.Tween({
              node: circle1, 
              duration: 1,
              x: xpos , 
              y: ypos, 
              easing: Kinetic.Easings.EaseInOut
            }).play();

              $('#container').bind('click touchstart', function() {
                CircleMovetoMouse()
               });

works perfect on desktop but not on smartphone and ipad. I need it really badly so it would be really great if someone can help. thanks in advance.

koyotee
  • 45
  • 8

1 Answers1

1

I think you need to use getTouchPosition() to get the touch coordinates. See the tutorial.

var touchPos = stage.getTouchPosition();

Also just FYI, the "click" equivalent for mobile events is "tap", not "touchstart".

$('#container').bind('click tap', function() {
  CircleMovetoMouse()
});

Touchstart <=> mousedown.

projeqht
  • 3,160
  • 3
  • 18
  • 32
  • 1
    In case anyone else finds this answer: `getTouchPosition` is NO LONGER part of Kinetic's API. It's been merged with `getMousePosition` and both should (theoretically) work on all devices. – Andrew May 19 '14 at 16:34