Sunday, August 28, 2011

[android-developers] Re: Spinning Wheel of Fortune Custom View and Animation



On Sunday, August 28, 2011 2:07:24 PM UTC-4, Rohit Ghatol wrote:

My requirements are as follows
1. The wheel starts spinning slowly
2. Spins for say 10-20 times
3. Slows down spinning at the end

How do I accomplish this, especially with the slow start, becomes
faster , 10-20 number of rotates and then slows down and stops?

Android Animation is no use here, since the acceleration interpolator
can not start slow, speed up and then slow down when we use
repeatCount.

Now that more or less leaves us with Updating the canvas by calling
view.invalidate() or use SurfaceView. I am more interested in how do
we control the animation timing  (even if we do it by hand) in code.
Most examples on the net are about fixed FPS, how do we do things when
spinning varies.

This is really more of a physics question, you want to model the physics involved with the acceleration and deceleration of the wheel.  Lets say you have a number of unique graphical frames representing the positions of the wheel as it spins, as each tick of the click goes by (assume you are displaying to a constant frame rate), calculate where the wheel should be (using your mathematical model -- which can indeed probably be implemented as a modified acceleration interpolator) and display the right frame.

Try measuring time since the beginning of the spin event and calculating which graphic should be shown based on your physics.

For example if the wheel is spinning at a constant speed, and at that speed you will show 30 unique graphical frames per second.  If it's spinning faster than that, you'll likely be showing fewer unique frames, but the position of the wheel will be moving faster, with some frames being shown more than once, since it will revolve more. If it's spinning slower than that, you'll be showing again less unique frames, but each frame might be displayed for longer, since it will revolve less.

A bad quick example, but I think it's the general idea.


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment