Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6241255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:44:01+00:00 2026-05-24T11:44:01+00:00

I have a question about cocos2d and box2d. I have to create a simple

  • 0

I have a question about cocos2d and box2d.
I have to create a simple wheel that rotate according how the user touch the wheel for an Ipad App.
I would like that according a certain touch movements the wheel start with a certain velocity, and after some rotation start to decrease velocity until it stops. (like a classic lucky wheel).

I need some hint. Do you think that is possible to do that using only cocos2d? Or I have to use Box2D? I already started to use Box2d, it’s very powerful, but is it possible to give an object a certain starting velocity rotation and after, let the world simulation to stop the object?

Thanks a lot!
Benza

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:44:02+00:00Added an answer on May 24, 2026 at 11:44 am

    When i developed the exact same thing on Android i also couldn’t find any useful examples/articles to implement this, so i did it like this:

    When a user touches the screen and does a fling/swipe (moves his finger across the screen and removes it from the screen) you calculate the speedX and speedY in pixels/second (in android you have a method onFling(float velocitY,float velocitX)).

    You then convert the speed which is in pixels/second to revolutions/second. This means that if the users fingered would traveled 1500 px in 1 second, your wheel would spin X times. For example if the fling/swipe speedX and speedY is 1500 px/s and your wheel has a radius of 150px, you calculate the wheel arc length like so:

          arc = r * PI. (r=150)
    

    Then you calculate the speed in revolutions per second like this:

         spinSpeed = Math.sqrt((speedX*speedX)+(speedY*speedY))/arc)*360   
    

    Once you have the speed you can change the wheel rotation angle every T miliseconds (i used 40miliseconds) like this:

         wheel.angle += spinSpeed;
    

    You also have to implement drag, so the wheel eventually slows down, like this:

         spinSpeed -= drag_value;
         wheel.angle += spinSpeed;
    

    You have to adjust the drag_value to your desired effect (how fast it slows down). You may also want to multiply the spinSpeed by a constant, so you get higher speed (i used 40).

    This implementation doesn’t include the wheel following the users finger. To do that you have to calculate for how much the users finger moved since the last touch of the screen (for X and Y coordinates). So you need 2 coordinates (lastTouchX,lastTouchY,newTouchX,newTouchY). When you have the coordinates you can calculate the slope or gradient of the lines that go through this coordinates (the slope/gradient is K in this formula: y = kx +n – standard line formula). Then you have to calculate the intersection angle between this two lines and apply it to the wheel. Something like this:

          tg = ((k1-k2)/(1+(k1*k2))); // k1 is the slope of the previous touch coordinate; k2 is the slope of the current touch coordinates                     
          angle =   Math.toDegrees(Math.atan(Math.abs(tg)));
          wheel.angle += angle; // to implement spinning in the other way use wheel.angle -= angle;
    

    Hope you get the idea

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have question about database optimizing, indexing. I have table that called projects and
I'm really sorry, I realize there have been several questions asked about cocos2d touch
I have a question about when you distribute your app with an existing DB.
I am new to Cocos2D and I have question about texuture loading. When I
Have a question about full text search. I have a query that works, but
I have a question about Url.Action. My position is on http://localhost/User/Edit and for some
I have a question about local classes in Java (classes that declares in the
https://stackoverflow.com/a/64983/468251 - Hello, I have question about this code, how made that working with
I have simple question about floating number, double temp; std::cout.precision(std::numeric_limits<double>::digits10); temp = 12345678901234567890.1234567890; std::cout
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.