-1

I have followed this tutorial(which includes speed and multi-threading) on how to move an image in android and so far so good. However I would like to know how to move the image in a circle ?

I have been modifying the update() method in the Droid class all day long ....to no avail.

public void update() {
        if (!touched) {

            x += (speed.getXv() * speed.getxDirection()); 
            y += (speed.getYv() * speed.getyDirection());

} }

Any help I would be forever grateful. Thanks You in advance.

AhabLives
  • 1,308
  • 6
  • 22
  • 34

1 Answers1

1

If you want to keep the concept of speed, you will need to alter the speed vector, changing it's direction but keeping it's magnitude, by an equal amount of degrees at every time interval. You have to make sure the update function is called at regular intervals. Something like this should work:

public void update()
{
    r = rFromXY(speed);
    t = tFromXY(speed);

    t += turningSpeed;

    speed.setXv(xFromPolar(r,t));
    speed.setYv(yFromPolar(r,t));

    if (!touched)
    {
        x += (speed.getXv() * speed.getxDirection()); 
        y += (speed.getYv() * speed.getyDirection());
    }
}

Where the aFromB functions convert between polar and cartesian coordinates. But if you want to write anything serious you should look into a physics engine.

Community
  • 1
  • 1
AlexDev
  • 4,049
  • 31
  • 36
  • Thanks for the help. I really do want to keep the multi-threading and speed. Could you point out which methods you think I have to modify and if possible how ? Thanks. – AhabLives Aug 06 '13 at 18:10
  • Yes, they should be Double. – AlexDev Aug 06 '13 at 19:46
  • Sorry for all the dumb questions Alex but graphics and animation are all new to me. Can I ask you to comment on these new Functions "rFromXY()" and "tFromXY()".....purpose\objective. And can I hard code "turningSpeed"? Thanks. – AhabLives Aug 06 '13 at 19:56
  • These two functions transform Cartesian (X,Y) coordinates to polar (r,t), where r is the magnitude of the speed and t is the angle, in radians. That way you can alter the direction of the speed and keep it's magnitude. TurningSpeed can be hardcoded, try something like 0.1. – AlexDev Aug 06 '13 at 20:19