I’m making a game with XNA.
I have my camera, my background and my scrolling class ready to go.
All i lack is to tell the scrolling to work when the camera position change. Is there a statement for that?
Like:
if (cameraposition.X ""Increases"")
{
Scrolling.Update()
}
Thanks.
You’ll have to keep track of the old camera position, and see if it changes. So your if would be:
At the end of every frame you want to update the oldCameraPosition variable, as such:
The difference between both positions is usually called the delta, or velocity. Now for the scrolling you might call your update with the camera Delta, so you scroll the same (or a modified amount). For example:
That way, every time the camera moves your background plane moves with it, at half speed. Do that trick 3 times with different modifiers and you’ll have a paralex effect.
Normally you’d want to use events for this, however an exception can be made for Game Development. Polling usually is the way to go, since you already have a game loop much like an event loop.
Either way, it would make more sense to just call
Scrolling.Update()whenever you change the position of your Camera in the first place.