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

  • Home
  • SEARCH
  • 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 9251215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:38:27+00:00 2026-06-18T10:38:27+00:00

I have created a circle with draw function in cocos2d, I am trying to

  • 0

I have created a circle with draw function in cocos2d, I am trying to detect touch point on circle line, lets say user touches bottom of the circle I want to print 270, if user touches top of the circle I want to print 90 etc….

I have looked this questions but they detect a sprite first then just compare if touches inside or outside of the circle

http://www.cocos2d-iphone.org/forum/topic/21629

how to detect touch in a circle

- (void) draw
{
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    glLineWidth(10.0f);
    ccDrawColor4F(0.2f, 0.9f, 0.02f, 0.6f);
    CGPoint center = ccp(winSize.width*0.88, winSize.height*0.8);
    CGFloat radius = 100.f;
    CGFloat angle = 0.f;
    NSInteger segments = 100;
    BOOL drawLineToCenter = YES;

    ccDrawCircle(center, radius, angle, segments, drawLineToCenter);
}

How can I detect a touch point on the circle line?

  • 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-06-18T10:38:28+00:00Added an answer on June 18, 2026 at 10:38 am

    Try this , didnt test the code , improved it according to your needs

    -(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent*)event
    {    
        CGSize winSize = [[CCDirector sharedDirector] winSize];
        CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
        CGPoint center=ccp(winSize.width*0.88, winSize.height*0.8);
    
        //now test against the distance of the touchpoint from the center change the value acording to your need
        if (ccpDistance(center, location)<100)
        {
            NSLog(@"inside");
    
            //calculate radians and degrees in circle
            CGPoint diff = ccpSub(center, location);//return ccp(v1.x - v2.x, v1.y - v2.y);
            float rads = atan2f( diff.y, diff.x);
            float degs = -CC_RADIANS_TO_DEGREES(rads);
            switch (degs) 
            {
                case -90:
                //this is bottom
                break;
                case 90:
                    //this is top
                    break;
                case 0:
                    //this is left side
                    break;
                case 180:
                    //this is right side
                    break;
                default:
                    break;
            }
        }   
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So we have a function DrawPoint(x,y) that draws a point, we have to draw
I have created a function that shows/hides different messages according to a combination of
I have created different shapes like circle/rect etc in my program using BufferedPaintDC on
I am trying to draw a continuous curved line in flash. There are many
In my app I need to draw a circle and user can drag it
I have created a program which draws a circle when I click on the
Say i wanted to create a variety of shapes consisting of a line, circle,
I have created a #logo DIV that consists of a smaller #circle DIV &
I have to draw 32 rectangles along a circle using html5, css3 and js.
I have created a QWidget with a bunch of QToolButtons in it and I

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.