Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a set of layers (each of them being a list of items) moving with different speeds as I mentioned here: 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.

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer
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). – Gabor Sep 27 '13 at 8:58
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. – LLL79 Sep 27 '13 at 21:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.