I'm a little confused over using integration to move a sprite. This is how I've always achieved this:
float time = 10f; //Number of seconds to pass a pre-defined area (using the screen width in this example) float velocity = 1f/time; //work out velocity based on above time float realX+=velocity*dt; //Move the sprite to the left (where dt is previously defined delta) x = realX*screenWidth //convert to screen coordinates so it can be rendered sprite.draw(x, y); //Working out the y position in the same way
Now, with the above code, there are 2 elements that are closely tied. Those being 'time' and 'screenWidth' - (of course, screenWidth could be replaced with another unit of distance such as a tile width in a tile-based game). However, It will always move the sprite at a speed that would take it 'time' (seconds) to cross 'screenWidth' (or whichever unit is specified).
However, I've been looking at various articles on Euler integration such as:
position = position + velocity * dt; velocity = velocity + ( force / mass ) * dt;
So, the first line is the same my method, but the second line is working out the velocity differently (using force/mass). Also, some examples I've seen have an 'acceleration' variable (which seems logical as I assume you could just then explicitly define the acceleration).
If I need to accelerate a sprite, I have been doing something like this:
And then working out the velocity again. So I'm using my time component to speed up or slow down my rate of acceleration. Not sure if this is correct.
I'm not great with physics so I would like to know - is my method valid? How would I use EULER with an 'acceleration' variable? Or how does force/mass come into play? Any help anyone could offer would be great.