Building up on the discussion from @UnderscoreZero's answer... You can have something like this:
public float testCollision(){
if (bottom of sprite1<top of sprite2)
return <top of sprite2>;
if(top of sprite1>bottom of sprite2)
return <bottom of sprite2>;
if(left edge of sprite1 > right edge of sprite2)
return <right edge of sprite2>;
if(right edge of sprite1 < left edge of sprite2)
return <left edge of sprite2>;
return 0; // or some value that cannot be attained by any return value and make sure you replace that value in the if condition below
}
newPos = currentPos + movement;
checkCollision = testCollision();
if(checkCollision != 0) { currentPos = checkCollision }
else { currentPos = newPos }
EDIT
This is fine, however, lets say that sprite1 hits from the right, the problem I have here is that the first condition (above) is still true. So....
sprite1_rightEdge>platformSprite leftEdge
So my sprite1 still gets positioned at the left edge of the platform......
The same also happens in reverse....
This is simple: Modify the collision check as follows:
if (top of sprite1<top of sprite2 && bottom of sprite1 > top of Sprite2)
return <top of sprite2>;
else if(top of sprite1<bottom of sprite2 && bottom of sprite1 > bottom of Sprite2)
return <bottom of sprite2>;
if(left edge of sprite1 < right edge of sprite2 && right edge of sprite1 > right edge of sprite2)
return <right edge of sprite2>;
else if(left edge of sprite1 < left edge of sprite2 && right edge of sprite1 > left edge of sprite2)
return <left edge of sprite2>;
A word of caution here... These conditions only checks for collision in one dimension, if you are going to have collision detection in two dimensions, like your image you may want to break the tie b/w position based on the direction of motion or any other parameter you define and have to modify the return values and conditions appropriately.