mariogarranz Posted December 26, 2013 Share Posted December 26, 2013 I am trying to add some physics to a dragged sprite. The idea is that, once the sprite stops being dragged, it will still keep some inertia from the dragging movement, so you can just throw sprites around by dragging them. I'm trying by simply saving a record of the sprite's previous position so that once the drag stops I can calculate the vector between current and previous update loop position and then apply that speed to the sprite. It's making things complicated, thought, and I was wondering if I was missing a simpler method built into Phaser for this same purpose, since I couldn't find anything in the docs. Thanks Link to comment Share on other sites More sharing options...
XekeDeath Posted December 26, 2013 Share Posted December 26, 2013 There is a history of pointer locations that is kept, but you need to turn that on. By default, it will record 100 entries at 100ms intervals.It will clear the history when the pointer is pressed down, and start dropping the first entries when full. Look into the docs on Phaser.Input for record, and you'll find the 3 variables associated with recording the pointer history. This history itself is stored in the _history array on the Phaser.Pointer object.The only differences between what you are doing and the above is that you are recording sprite positions, this records mouse positions; and you only record the last position, this records (by default) 100 positions... As for built in ability to throw things around, I don't believe there are any, and you need to do it manually... mariogarranz 1 Link to comment Share on other sites More sharing options...
mariogarranz Posted December 26, 2013 Author Share Posted December 26, 2013 There is a history of pointer locations that is kept, but you need to turn that on. By default, it will record 100 entries at 100ms intervals.It will clear the history when the pointer is pressed down, and start dropping the first entries when full. Look into the docs on Phaser.Input for record, and you'll find the 3 variables associated with recording the pointer history. This history itself is stored in the _history array on the Phaser.Pointer object.The only differences between what you are doing and the above is that you are recording sprite positions, this records mouse positions; and you only record the last position, this records (by default) 100 positions... As for built in ability to throw things around, I don't believe there are any, and you need to do it manually... Yeah, that's exactly the kind of functinality I was looking for. Since movement is the same for both pointer and sprite, it will work as well.Thank you very much Link to comment Share on other sites More sharing options...
mariogarranz Posted January 15, 2014 Author Share Posted January 15, 2014 OK, so I managed to make some sort of game physics using pointer history and everything seemed to work fine. Then I tried it on a mobile phone and it didn't work at all. I'm guessing the pointer history for mouse does not work with touch events, but can't seem to understand the way input pointers work, if I can use another one to track touch event history or if I should do it another way. Any ideas? EDIT: Stupid me, I just saw pointer1 .... pointerx are touch pointers. Fixed, thanks Link to comment Share on other sites More sharing options...
efusien Posted September 17, 2014 Share Posted September 17, 2014 Hi mariogarranz, Can you share a working code example here?I'm curious how you did the inertia from the dragging movement :-)Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts