I'm moving my sprites using the following formula:
Code that I'm using (Only shows sprite's X position being calculated but Y position is also being done)
spriteGridX = 240/480; //I start out with a virtual 'Grid' so I can scale position to all resolutions etc so 240/480 would place the sprite at the center of the screen (X) spriteScreenX = spriteGridX * width; //Scale to physical screen where width is the width of the current devices screen (viewport) spriteXTime = 8f; //8 being the amount of time in seconds that this sprite will take to traverse the entire width of the screen spriteXVel = 1/spriteXTime; //Velocity that will be used to move the sprite along the virtual grid position
So, when I need to move the sprite, I simply do the following:
spriteXGrid+= (spriteXVel * Delta) //+= for right -=for left. I'm using a fixed delta time spriteScreenX = spriteGridX * width; //And again, convert to usable screen position for current device drawsprite(spriteScreenX, SpriteScreenY); //Draw the sprite (drawSprite is just a method I've written to draw openGL quads and it takes the screen X and Y as coordinates - spriteScreenY not shown here but essentially same as X with height instead of width.
The above seems to work OK (if I specify, as above, 8seconds, then the sprite does indeed take 8seconds to pass the whole screen as far as I can tell).
However, a problem becomes evident when I have 2 sprites (in my case, 2 horizontally moving platforms, both starting at the outer edges of the screen - one on the left and one of the right) - these move towards each other and when they 'meet', they go back in the opposite direction, and again when they reach their initial starting positions.
After the second time, they start to move slightly out of sync and the problem accumulates. Each platform has the same time/velocity settings and it seems that a sprite over the right side of the screen moves at a very slightly different speed than the one on the left.
After the initial move, the difference between the grid positions of my 2 sprites are a follows:
Left sprite = 0.002083334 Right sprite = 0.0020834
I can't work out why there is a difference. They're using the same formula.
Of course the problem could be that they are reversing at slightly different times and not the speed as I suspect, but for now I've ruled that out as they seem to be reversing correctly.
Be grateful if anyone could assist. Thanks
Test Device: Google Nexus 10, Samsung Galaxy Ace v1