Rotate sprite around other sprite using dragging and radio

i am trying to create a game using two sprites that rotate like a earth the sprite and the moon the sprite that rotate with a radio around earth using dragging. how can make a radio to the earth for the moon sprite only rotate around the earth with a specific radio?

A radius?

yes a radius like a planet with the moon

You will need trigonometry for this.

When the drag starts (TouchDown), calculate the current radius from the earth sprite to the moon sprite using the Pythagorean formula.

As you drag the moon, calculate the angle between the moon and earth based on the Canvas direction system.

Use that angle and the Pythagorean length to reposition the moon, using sin() and cos() functions.

Here is one way to do it.

orbit.aia (2.3 KB)

Get the angle when the ball is moved, then set the position of the ball from the angle, taking into account the x/y positioning of a canvas.