SPOILER ALERT: This post will show you how to move the ball at double speed, and how to move the ball directly to where you clicked on the screen.
There are several ways to move the ball at double speed. I think it is best to do this in the updateGame method:
Here the position of the ball is changed depending on the speed of the ball. If that is multiplied by two, then it will move faster:
This would do the trick! Notice that I don’t need brackets because the precedence of the *’s mean that they will be performed before +.
However there is a small problem. Now the mBallSpeedX and mBallSpeedY actually aren’t reflecting pixel/sec any more. If you want to keep that then you need to multiply the evaluation of mBallSpeedX and mBallSpeedY, for instance in actionOnTouch:
You could change that to:
Notice I use brackets to enforce that the – operation happens before the *.
You would also need to change in actionWhenPhoneMoved to:
To change the ball’s behaviour to move instantly is actually simpler. In actionOnTouch you would need to move the ball directly to the x and y position of the touch. You do that this way:
We prefer discussions about the code in FutureLearn, so I will not publish comments here. I hope you understand 😉