Why is bg2Pos the value it is?

in the video, the value for bg2Pos is:

Vector2 bg2Pos{bgX + (background.width*2), 0.0};

wouldn’t that be putting the second background a whole extra space the size of the background picture away? why wouldn’t there be a big white gap there? I ran the program, and there is no gap, so it is obviously a gap in my understanding. the dimensions are 256*192. so why wouldn’t it be bgX + background.width + 1?

Good thinking. However, we’re drawing the image scaled by 2.0, see the arguments of the DrawTextureEx call.

And we don’t add +1 because we start counting at 0. If you draw into 10 pixels starting from pixel number 0, you fill pixels 0, 1, 2, …, 9.

ahhhh! that’s what I didn’t connect the dots on. you’re right, the image is being scaled 2x, so the background width is doubled. of course. so if it was just a normal scaled image it would bgX + background.width.

thank you so much!

that also make sense for the width. a 256 pixel wide image starts at pixel 0 and 255 is the last column. bgX + background.width would line it up at 256, and my thought of +1 would leave a 1 pixel wide white line.

1 Like

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

Privacy & Terms