Hello! If this is your first time reading about my thirty day developer challenge, click here to go to the first post!
Flick works! Hurray!
Ok, actually it doesn't work perfectly just yet. For the most part it works, except in the cases where I flick the mouse too quickly, then the behavior gets a bit wonky.
What I am doing is keeping a historical record of the past 100 milliseconds of the mouse locations on the screen while the mouse is pressed. Then I am finding the deltas of each two points and adding them together to create a velocity for the object. Then I assign that velocity to the object when the mouse button is released.
I was able to get the idea for the above method from this post. (Thank you Rich from Phaser forums!)
Unfortunately, the method isn't perfect. For example, let's say I move the mouse to the right 500 pixels and then move it quickly a 100 pixels to the left, then the object will still move to the right upon release because the way I calculated was to average up the last 100 milliseconds.
In other words, let's just say that if I've been moving to the right (positive x-axis, positive x-velocity) for four seconds, then switch at the last second to the left (negative x-axis, negative x-velocity) the four seconds of positive x-velocity will overshadow the last second of negative x-velocity. Thus the object will move to the right upon release, although it should move to the left because that's the direction it was travelling in last.
I am satisfied for today though. You can't climb an entire mountain in one day, you have to take it one small step at a time.
On a side note, feels good to get this far already!
Comments
Post a Comment