Jump to content

Drag sprite in mobile device


jordibar
 Share

Recommended Posts

I don't know how to drag sprites in touch device, I'm trying something like that:

 

function Play() {}  Play.prototype = {    create: function() {            this.game.add.sprite(0, 0, 'background1');      this.fitxa1 = this.game.add.sprite(100, 250, 'fitxa1');      // Input Enable the sprites      this.fitxa1.inputEnabled = true;      // Allow dragging      // enableDrag parameters = (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite)      this.fitxa1.input.enableDrag();      //this.fitxa1.input.onDown.add.enableDrag();      //  Enable snapping. For the atari1 sprite it will snap as its dragged around and on release.      //  The snap is set to every 32x32 pixels.      // enableSnap(snapEvery32PixelsOnX, snapEvery32PixelsOnY, snap on drag, snap on released)      this.fitxa1.input.enableSnap(15, 15, false, true);      // Mobile      this.game.input.onDown.add(this.toDrag, this);    },    update: function() {    },    clickListener: function() {      this.game.state.start('gameover');    },  toDrag: function(){    // Input Enable the sprites      this.fitxa1.inputEnabled = true;      // Allow dragging      // enableDrag parameters = (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite)      this.fitxa1.input.enableDrag();      //  Enable snapping. For the atari1 sprite it will snap as its dragged around and on release.      //  The snap is set to every 32x32 pixels.      // enableSnap(snapEvery32PixelsOnX, snapEvery32PixelsOnY, snap on drag, snap on released)      this.fitxa1.input.enableSnap(15, 15, false, true);      console.log('Hola');    }  };

but it doesn't work, can you help me please??!

 

Thank you!

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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