Since having the background disappear is not the way it is meant to be, we will add an infinite background. One way to do it is to load as large a background as the memory allows and hope the player loses before reaching the end of the background image. But there is a much better way. We will have relatively small background segments, and when the background segment is going to end, we will create a new one and attach it to the end of the current segment. When the old one goes off the screen, it is removed and destroyed.
This way, we will have only two backgrounds in memory at any time, and this makes it easier and simpler to manage.
First we need to adjust the
zPosition property of the player and the
Background object. ...