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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:56:16+00:00 2026-05-26T23:56:16+00:00

since i havnt got an answer in my previos post, and no one solve

  • 0

since i havnt got an answer in my previos post, and no one solve that problem , i am asking this again. there is no 1 explanation regarding this.

i need to detect a sprite touch, a SPECIFIC one. in cocos2d+box2d.

lets say i have sprite CCSprite *ran that has a body, BUT , i have many of it .

if i detect a touch with the ccTouchesBegan , and use the if(CGRectContainsPoint(particularSpriteRect, currentPosition))

i will detect the touch in ran but i dont know who ran is this from all, and i need to destroy than specific ran , which i cant know who it was .

i find the best way to do that, as i do with contact listener that gives me the specific sprite user data :

CCSprite *actora = (CCSprite*)bodyA->GetUserData();   
CCSprite *actorb = (CCSprite*)bodyB->GetUserData();

and then i know that actora is what needs to be destroy cause i have his user data.

[self removeChild:actora cleanup:YES]; 

so , again , i need to detect a sprite touch and KNOW who it was,cause i have many ran's.
i guess its something needs to involve the userData .

any direction please ?
thanks alot.

  • 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-26T23:56:17+00:00Added an answer on May 26, 2026 at 11:56 pm

    ok, i have got it :

    this is what i do, to destroy the specific body, different from what was said here :

    put the next code in the touch method :

    CGPoint currentPosition = [touch locationInView: [touch view]]; 
     currentPosition = [[CCDirector sharedDirector] convertToGL: currentPosition];
    
        b2Vec2 locationWorld = b2Vec2(currentPosition.x/PTM_RATIO, currentPosition.y/PTM_RATIO);
    
        for (b2Body* b = world->GetBodyList(); b; b = b->GetNext()) 
        {
            b2Fixture *bf1 = b->GetFixtureList();
            if (bf1->TestPoint(locationWorld))
            {
                CCSprite *tempSprite = (CCSprite *) b->GetUserData();
                if (tempSprite .tag==2 || tempSprite .tag==3) 
                {
                    [self removeChild:tempSprite cleanup:YES];
                    world->DestroyBody(b);
    
                }
            }
        }
    

    here if you touch the right sprite(tagged) , it get destroyed .

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

Sidebar

Related Questions

Im amazed that even after all this time (jQuery has been around since 2006
Since CS3 doesn't have a web service component, as previous versions had, is there
I guess this question of mine is pretty basic but since Ive never done
I'm having a problem with a code that doesnt follow sequential execution although I'm
I have been trying to solve this for 2 weeks and I have not
This is closely related to anothewr question I have asked but since this is
heres a problem of jQuery that has been haunting me for a long time,
On one hand, I'm told that exceptions in C# are 'expensive', but on the
Since I started writing this question, I think I figured out the answers to
Since named parameters are those parameters that are identified by their explicit name, instead

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.