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 933553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:51:09+00:00 2026-05-15T20:51:09+00:00

How would one detect a touch on a rotated CCSprite? I am familiar with

  • 0

How would one detect a touch on a rotated CCSprite?

I am familiar with the general technique of using ccTouchesBegan and contentSize, anchorPoint etc. to have a sprite detect if a touch was within its bounds … but I am not sure how to proceed once the sprite has been rotated by some angle.

I want the sprite itself to detect the touch (encapsulation) and report the event via a delegate to another object.

If anyone has some code to share … would be great.

  • 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-15T20:51:09+00:00Added an answer on May 15, 2026 at 8:51 pm

    Try using the CCNode convertTouchToNodeSpaceAR: method to convert the point to the rotated coordinates and then you can do the compare of the sprite bounds.

    I made this a category on CCNode so it’s available to any CCNode or subclass.

    @interface CCNode (gndUtils)
    
    // Lets a node test to see if a touch is in it.
    // Takes into account the scaling/rotation/transforms of all 
    // the parents in the parent chain.
    // Note that rotation of a rectangle doesn't produce a rectangle 
    // (and we are using a simple rectangle test)
    //   so this is testing the smallest rectangle that encloses the rotated node.
    // This does the converstion to view and then world coordinates
    // so if you are testing lots of nodes, do that converstion manually
    //
    //  CGPoint touchLoc = [touch locationInView: [touch view]];  // convert to "View"
    //  touchLoc = [[CCDirector sharedDirector] convertToGL: touchLoc]; // move to "World"
    // and then use worldPointInNode: method instead for efficiency.
    
    - (BOOL) touchInNode: (UITouch *) touch;
    
    // allows a node to test if a world point is in it.
    - (BOOL) worldPointInNode: (CGPoint) worldPoint;
    
    @end
    

    and the implementation:

    @implementation CCNode (gndUtils)
    
    - (BOOL) touchInNode: (UITouch *) touch
    {
        CGPoint touchLoc = [touch locationInView: [touch view]];            // convert to "View coordinates" from "window" presumably
        touchLoc = [[CCDirector sharedDirector] convertToGL: touchLoc];     // move to "cocos2d World coordinates"
    
        return [self worldPointInNode: touchLoc];
    }
    
    - (BOOL) worldPointInNode: (CGPoint) worldPoint
    {
        // scale the bounding rect of the node to world coordinates so we can see if the worldPoint is in the node.
        CGRect bbox = CGRectMake( 0.0f, 0.0f, self.contentSize.width, self.contentSize.height );    // get bounding box in local 
        bbox = CGRectApplyAffineTransform(bbox, [self nodeToWorldTransform] );      // convert box to world coordinates, scaling etc.
        return CGRectContainsPoint( bbox, worldPoint );
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would one go about either using the 3D components of WPF or using
How do I isolate touch events from each other? For example, I have one
How would one detect a mouse click inside of an arc drawn in a
I have an object observer that I only need to detect one thing. Once
We are using CRM 2011 w/ ADFS 2.0. Our users would like for one
Can the iphone detect its movement in terms of distance? Would one be able
How would one enumerate the installed browsers on an OS X system from a
How would one switch a public bool to true from a child form in
How would one follow the proper steps in order to license a package under
How would one typically implement a service layer in an MVC architecture? Is it

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.