0
\$\begingroup\$

I have a set of layers (each of them being a list of items) moving with different speeds as I mentioned here: https://stackoverflow.com/a/18962019/270197. Layers back in the scene move with slower speed than those in the front. The position of items in the front layer is calculated from VelocityTracker.getYVelocity() (we are not doing infinite scrolling but responding to the user's gestures) by using standard Euler integration with friction applied to decrease the velocity by a fixed number of percent each frame.

I would need a similar dynamics class for the background layers that act as a satellite, that is, movement should gracefully finish at the same time so instead of an abrupt pause, the velocity of the slower layers should dynamically adjust to the top layer's velocity on each frame (reaching 0 together) to create a realistic but synchronized fling movement on each layer. Any ideas about the algorithm to achieve that?

Update: it is implemented now on github.

\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

To keep the scroll velocity of each layer related to each other layer, I'd calculate the velocity of the top layer and then modify it by the relative depth of the current layer you're evaluating. Something like:

layer_velocity = mVelocity * (1.0 - layer_depth)

where layer_depth is ranged 0.0 (top or surface level) to 1.0 (bottom or deepest level)

Notice that you won't get any movement at 1.0 depth, possible floating point errors aside, so you would either want to set your actual deepest layer to something less than 1.0, or modify the calculation to accommodate a depth of 1.0 while still providing a non-zero velocity result.

\$\endgroup\$
2
  • \$\begingroup\$ thanks @lll79 but it doesn't work: your calculation only adds a little delay plus it does not take into account the different friction applied to the different layers (and the whole point is that they should scroll at different speeds, due to different friction applied, but reach their end-point simultaneously -- wherever that happens to be within the list -- while maintaining a realistic fling movement). \$\endgroup\$
    – Gabor
    Sep 27, 2013 at 8:58
  • \$\begingroup\$ Instead of applying a different friction to each layer to achieve different scroll rates, it assumes you apply a single friction value to a velocity that is shared between all layers, and find the scroll rate of each layer by interpolation, using their relative depth. \$\endgroup\$
    – LLL79
    Sep 27, 2013 at 21:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .