One way to do it is to schedule a selector to run periodically, and when it's called, move your sprite over the circle.
To do that, you can take a look at the functions at CGPointExtension.m
. In particular, you can use ccpForAngle
, ccpMult
, and ccpAdd
. You could do something like this:
// Assume the class is a subclass of CCNode, and has the following properties:
// radius: the radius of the circle you want the sprite to move over.
// circleCenter: the center of the circle
// currentAngle: the angle where the sprite currently is
- (void)tick {
float anglePerTick = 0.1; // this will determine your speed
currentAngle += anglePerTick;
self.position = ccpAdd(ccpMult(ccpForAngle(currentAngle), radius)),
circleCenter);
self.rotation = currentAngle * 180 / M_PI; // Convert from radians to degrees
}
The main problem with this approach is that you are setting the angular velociy as a constant, so if the circle gets bigger, the "distance" the sprite will travel on each tick will increase, and may lead to flickering.