Take the 2-minute tour ×

I'm implementing a Contact Listener with Box2d which is a C++ .mm file.

Whenever two bubble's collide, I want to know so I can execute something. Here is my code:

void ContactListener::BeginContact(b2Contact* contact)

    b2Body* bodyA = contact->GetFixtureA()->GetBody();
    b2Body* bodyB = contact->GetFixtureB()->GetBody();
        BubbleSprite* bNodeA = (BubbleSprite*)bodyA->GetUserData();
        BubbleSprite* bNodeB = (BubbleSprite*)bodyB->GetUserData();

        BOOL oneIsBeingTouched;
        if(bNodeA.isDrag == YES || bNodeB.isDrag == YES) oneIsBeingTouched = YES;

BubbleSprite's have the property BOOL isDrag which indicates whether or not they are currently being dragged by a user. The problem I get is:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[CCSprite isDrag]: unrecognized selector sent to instance 0x1ed504a0'

BubbleSprite is a subclass of CCSprite. isDrag is properly declared and synthesized in its file. Does anyone have any ideas on what's going on? Thanks

share|improve this question
here stackoverflow.com/questions/10968425/… is another similiar problem today, fixed by restarting xcode and reimporting certain files to project. –  rokjarc Jun 10 '12 at 14:31
You mention that this code is for "whenever two bubble's collide", but you are not checking that the collision is between two bubbles. If every body in the world is a bubble then this would still be ok, but otherwise you cannot assume that the collision is between two bubbles. –  iforce2d Jun 10 '12 at 20:45
add comment

2 Answers

Try using

 if (bNodeA.drag == YES) ...


if ([bNodeA isDrag] == YES) ...
share|improve this answer
Same error. Unrecognized selector on CCSprite. It should be run on a BubbleSprite... –  user339946 Jun 10 '12 at 11:12
Are you adding drag property yourself with subclassing? Neither CCSprite nor CCNode have it. –  rokjarc Jun 10 '12 at 11:16
Yes, isDrag is the property name. As I mentioned, BubbleSprite is a subclass of CCSprite. –  user339946 Jun 10 '12 at 11:21
if you named the property isDrag it will be accessible via [node isIsDrag]. check stackoverflow.com/questions/4864239/using-a-bool-property –  rokjarc Jun 10 '12 at 11:23
Ah, interesting, didn't know about the "is" prepending. Anyway, I renamed it to just "drag" for simplicity. However, I still get the same message. Its asking a CCSprite for the drag property when it should be asking a BubbleSprite and then throwing the unrecognized selector error. Not sure why...Thanks –  user339946 Jun 10 '12 at 11:46
show 1 more comment

I suggest using a getter, Create your property like so.

@property (nonatomic, assign, getter=isDrag) BOOL dragging;

and of course, @synthesize it. Now you can use -setDragging: and [bNodeA isDrag]. Nothing serious, but should make for easier to understand code.

share|improve this answer
add comment

Your Answer


