Bug in sprite positioning on screen initialization, but not after

Movement of the player forward is emulated by moving road dashes backward and resetting them to the top once they reach the bottom of the screen.

This code is run on screen.initialize to position the road dashes correctly(evenly spaced). Note that global Road_Dashes is a list of all road dash sprites:


This code resets each road dash to the top of the screen when it hits the bottom.

Here is the result.

The road dashes are a bit too far to the right when the app starts(road dashes circled in red), and are correctly positioned when they are reset to the top(road dashes circled in green). The math finding the x-position is the same between the screen.initialize code and the code resetting the road dashes to the top, so I am not sure why I am getting different results.

This is a well-known issue.
When Screen initialized, the canvas initialize not finished.
Use a clock to wait about 100-200ms. then set the position of image Sprite.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.