Move circle in c++

How can i move circle a sprite ?

Have you read Programming guide ? or do you have specific case ? tell us more information,please.
http://www.cocos2d-x.org/programmersguide/4/index.html

I want move a sprite along a circle. lt like this
http://lea.verou.me/2012/02/moving-an-element-along-a-circle/

This is something which you will not be able to achieve by Actions. Here’s a few steps without dwelling into the code:

  1. You will need to schedule an update function to move your sprite.

  2. You will need to know the centre of the circle which your sprite is moving along.

  3. You will need to apply the parametric equation of a circle to find the X and Y of the sprite. http://www.mathopenref.com/coordparamcircle.html

  4. Based on the above, the only variable you need to update is the angle for the equation. The way you update should look something like this:

    #define ROTATION_SPEED 30.f //30 degrees per second

    void LayerTest::update(float dt)
    {
    totalTimeElapsed += dt;
    angleNow = totalTimeElapsed * ROTATION_SPEED;
    //apply the parametric formula to find the X and Y
    sprite->setPosition(Vec2(x, y));
    }

Hope it helps.

1 Like