Well, I think you're just confusing yourself by not clearly distinguishing between

**position** and

**movement**. The thing you need to store is the

**position** (which we can also represent as "how far along we are": a proportion of the total distance), and then you just use the movement speed to update the position.

There are lots of different ways to figure out how to do that update (some of which are more efficient to calculate), but let's take a general example, where you want to move from point

x_start,y_start to

x_end,y_end, and we store it as a proportion. To calculate a position

x,y that is

proportion of the way between, you can do it like this:

// Variables declared either globally or as function arguments

int x_start, x_end, y_start, y_end;

float proportion;

// Calculation of coordinates

int x = FloatToInt(IntToFloat(x_end) * proportion + IntToFloat(x_start) * (1.0 - proportion), eRoundNearest);

int y = FloatToInt(IntToFloat(y_end) * proportion + IntToFloat(y_start) * (1.0 - proportion), eRoundNearest);

We do all the calculation in floats for maximal accuracy, and then round off to the closest int. You see that we just take a weighted average of the start and end coordinates, according to the proportion (when

proportion is 0, we use 100% of the start coordinate and 0% of the end coordinate, when it is 0.1 it's 90% to 10%, and so on).

OK, now we just need to update the proportion, which is pretty simple:

float proportion;

void MoveBackdrop(CharacterDirection direction, float speed)

{

if (Backdrop == null || direction == eDirectionNone) return;

// Update the proportion by a certain amount (the movement speed)

proportion = proportion + speed;

// Make sure the proportion is in the [0.0, 1.0] range

if(proportion > 1.0)

proportion = 1.0;

else if(proportion < 0.0)

proportion = 0.0;

// We set x/y_start/end with the particular values for the movement we want

if(CharacterDirection == eDirectionDownLeft)

{

int x_start = Room.Width * 2;

int y_start = 0;

int x_end = Room.Width;

int y_end = Room.Height;

}

else if(CharacterDirection == eDirectionDownRight)

{

// etc.

}

// etc.

// Calculate the coordinates from the proportion

int x_offset = FloatToInt(IntToFloat(x_end) * proportion + IntToFloat(x_start) * (1.0 - proportion), eRoundNearest);

int y_offset = FloatToInt(IntToFloat(y_end) * proportion + IntToFloat(y_start) * (1.0 - proportion), eRoundNearest);

// Render

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();

surface.DrawImage(x_offset, y_offset, Backdrop.Graphic, 0);

surface.Release();

}

This all assumes that the CharacterDirection doesn't change during the scrolling. If it does, it'll suddenly jump from one position to another when it changes direction.