Jump to content

How to set start position of element after dragging?


weratius
 Share

Recommended Posts

I have an element which must be dragged. Also it is important to set start coordinates to this element after it's dragged.

So, I do like this, but nothing happens at all

Also the coordinates stay the same after dragging and I wonder why it is so

At first I used the ...body.x and so on, but nothing happend too, maybe I do something wrong?

var droid;var someObj = {   START_X: '',   START_Y: '',    init: function() {     droid = game.add.sprite(profile.x - 240, profile.y + 150, 'droid', profileGroup);     droid.fixedToCamera = true;     droid.anchor.set(0.5, 0.5);     this.initPhysics();   },   startDrag: function() {    console.log('start');     droid.body.moves = false;      this.START_X = droid.x;    this.START_Y = droid.y;    droid.z = 200;    console.log('********START*******');    console.log(droid);     console.log('DROID = ',droid.x, droid.y);    console.log('START = ',this.START_X, this.START_Y);   },   stopDrag: function() {    droid.body.moves = true;       droid.x = this.START_X;    droid.y = this.START_Y;    droid.z = 75;    console.log('********STOP*******');    console.log(droid);     console.log('DROID = ',droid.x, droid.y);    console.log('END = ',this.START_X, this.START_Y);   },  initPhysics: function() {    console.log('create');    game.physics.arcade.enable(droid);    droid.inputEnabled = true;    droid.input.enableDrag();    droid.events.onDragStart.add(this.startDrag, this);    droid.events.onDragStop.add(this.stopDrag, this); }}

Couldn't you help me to solve this problem?

I will really appreciate that!

Thank you!

Link to comment
Share on other sites

I'm feeling a red flag coming at: 

stopDrag: function() {    droid.body.moves = true;       droid.x = this.START_X;    droid.y = this.START_Y;

You're assigning the droids new post-drag position to the starting position values. This would essentially snap the droid back to it's starting position, would it not?

 

You shouldn't need to set the droid's coordinates manually after dragging either, they will update automatically while it's dragged.

Link to comment
Share on other sites

I'm feeling a red flag coming at: 

stopDrag: function() {    droid.body.moves = true;       droid.x = this.START_X;    droid.y = this.START_Y;

You're assigning the droids new post-drag position to the starting position values. This would essentially snap the droid back to it's starting position, would it not?

 

You shouldn't need to set the droid's coordinates manually after dragging either, they will update automatically while it's dragged.

 

jonoco I just need to return my droid to the start position after dragging

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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