I'm making a game where you have a plane and you need to control it, nothing complicated. I want to have two buttons, up and down so when I press up for example the plane will smoothly go up until I release the button. Currently I have an animation that moves the plane up and down and I trigger the animation when I press the button. This solution is not the best as when I release the button, the plane doesn't stay at the exact position he stopped at.
downBtn.Touch += (s, e) =>
{
var handled = false;
if (e.Event.Action == MotionEventActions.Down)
{
//plane.SetY(plane.GetY() - 10);
int[] imageCoordinates = new int[2];
plane.StartAnimation(planeMoveDown);
handled = true;
}
else if (e.Event.Action == MotionEventActions.Up)
{
int[] imageCoordinates = new int[2];
plane.GetLocationOnScreen(imageCoordinates);
int y = imageCoordinates[1];
plane.SetY(y+145);
plane.ClearAnimation();
handled = true;
}
e.Handled = handled;
};