Jump to content

Dragged Sprite physics


mariogarranz
 Share

Recommended Posts

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

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...

Link to comment
Share on other sites

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

  • 3 weeks later...

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

  • 8 months later...
 Share

  • Recently Browsing   0 members

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