Center object on Screen - background moves instead of object.

Imagine a bowling game where the camera is positioned directly above the bowling ball.

When the user “throws” the ball it always stays in the middle of the screen, but the background moves until the physics of the ball stops it from moving.  

I know how to apply a force on the ball to make it move… any suggestions on how to apply that force so that the object stays still and only the background moves?

Thanks in advance.

Hi Byron,

Here are two ideas:

  1. Apply the opposite force to the background instead of the ball, so the background moves whilst the bowling ball stays in the same place (obviously, the size of the force would have to be scaled appropriately).  Your bowling ball would still be a physics object that could interact with the background.

  2. Set up an enterFrame listener that alters the position of the background and ball every time a frame is drawn.  You shift the background in the opposite direction to the ball (ie. if the ball has moved up the screen by 20 pixels, the background is pulled down by the same amount) and then you reposition the ball back the centre.

Kind regards,

Simon

Excellent suggestions. I wonder how badly performance would be affected by using option 2? Seems like a simple solution.

Thank you

Hi Byron,

Here are two ideas:

  1. Apply the opposite force to the background instead of the ball, so the background moves whilst the bowling ball stays in the same place (obviously, the size of the force would have to be scaled appropriately).  Your bowling ball would still be a physics object that could interact with the background.

  2. Set up an enterFrame listener that alters the position of the background and ball every time a frame is drawn.  You shift the background in the opposite direction to the ball (ie. if the ball has moved up the screen by 20 pixels, the background is pulled down by the same amount) and then you reposition the ball back the centre.

Kind regards,

Simon

Excellent suggestions. I wonder how badly performance would be affected by using option 2? Seems like a simple solution.

Thank you