Drag and drop static element

Apr 5, 2012 at 8:13 PM


I am working on a project where i have to drag and drop STATIC shape. I am using MouseDragElementBehavior. When i add that bahavior to shape it is no more static. Please help! 

Apr 24, 2012 at 2:27 PM
Edited Apr 24, 2012 at 2:39 PM

I am not sure the best way but you should be able to change the Static body position.

There are many ways you can do this. Easiest way would be to activate a mouse move event on a canvas when the object is clicked and capture the point "convert to Vector2" where you want it to go from the mouse position argument and update the object.position to this point in the event.

Another way that I normally use but it is hard to explain is to grab the object based on a click and get the mouse position as the start point and also in that click event start a manipulation delta that updates the start point until manipulation is completed. In the game tick check that the object has been clicked with a bool and update the position to the vector2 "converted from the point" and when the manipulation is completed set the bool to check back to false. This way seems to perform much better if it is happening during collisions and chaos haha, although it should not partake in them since it isn't using physics behaviors. If you want it to partake you can use the same method but make it not static while updating and apply force to point and then when set change it back to static.