I've encountered really strange issue with if statement. I got image in canvas, which i want to move/drag with mouse/touch. Movement of image works fine. I want to add boundaries, so image would never leave viewport.. image is scaled (its height) to height of canvas, so I just need to add left and right border..
if (planTranslate.X < 0)
{
planTranslate.X = 0;
}
else planTranslate.X = startPosition.X - vector.X;
if (planTranslate.X > maxX)
{
planTranslate.X = maxX;
}
else planTranslate.X = startPosition.X - vector.X;
First condition works as expected, but second does not and I have no idea why..
when i put if planTranslate.X > maxX before if planTranslate.X < 0 image stops on right side of viewport but keep going on left.
Any suggestions or help would be greatly appreciated.. thx in advance..
Aucun commentaire:
Enregistrer un commentaire