Sign in to follow this  
lorno

How to manually trigger dragging event?

Recommended Posts

Note: I'm using lodash utility library together with Phaser

 

I wanted to trigger the dragging event of a sprite after a "long press" event from an onInputDown event which is determined on the update function via a delta property. The problem is, the dragging event is not triggered after enabling it using card.input.enableDrag(). I've also used the dispatch() function that looks like this: card.events.onDragStart.dispatch(), the dragging will start but it will not update the position of the sprite. I also wanted to disable the dragging after onDragStop, so that I can "long press" it again and enable dragging.

var card;create: function() {  // Initialize card sprite  card = this.add.sprite(x, y, 'card');  card.inputEnabled = true;  // Add Event Handlers  card.events.onInputDown.add(eventCardInputDown);  card.events.onDragStart.add(eventCardDragStart);  card.events.onDragStop.add(eventCardDragStop);  // Set delta for long press to null  card.delta_long_press = null;},update: function() {  // Check if card is not yet draggable and delta_long_press is not null  if(card.input.draggable == false && !_.isNull(card.delta_long_press)) {    var timesince = _.now() - card.delta_long_press;    // Check if timesince is greater than or equal to a second    // Then enable dragging of the card    if(timesince >= 1000) {      card.input.enableDrag();    }  }},eventCardInputDown: function() {  // Set delta_long_press to now  card.delta_long_press = _.now();},eventCardDragStart: function() {  console.log('DRAG START');  // Some code},eventCardDragStop; function() {  console.log('DRAG STOP');  // Some code}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.