gameprogcpp / code

Game Programming in C++ Code
Other
1.01k stars 354 forks source link

Fix bug in Chapter2/BGSpriteComponent.cpp #58

Open HarIgo23 opened 6 months ago

HarIgo23 commented 6 months ago

I found a bug in Update BGSpriteComponent.cpp and suggest fix of its. The bug:

bg.mOffset.x = (mBGTextures.size() - 1) * mScreenSize.x - 1;

If mScrollSpeed will high, for example 600, it makes gap between two background. Cause -1 at the end of the formula is hack that makes sense only when mScrollSpeed is low.

image

My fix keeps diff between bg.mOffset.x and width, if it more than 1px.

bg.mOffset.x += mScreenSize.x * mBGTextures.size();