0

after I upgraded my project to SpriteBuilder 1.1 and Cocos2d v3.1 the following code stopped working:

    -(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    CGPoint touchLocation = [touch locationInNode:_contentNode];

    //Not working
    if (CGRectContainsPoint([_arbolNegro boundingBox], touchLocation)) {
        _mouseJointNode.position = touchLocation;
        _mouseJoint = [CCPhysicsJoint connectedSpringJointWithBodyA:_mouseJointNode.physicsBody bodyB:_arbolNegro.physicsBody anchorA:ccp(0, 0) anchorB:ccp(10, 50) restLength:3.f stiffness:3.f damping:0.f];
    }
}

I assume that the problem is whit the CGRectContainsPoint because when I eliminate the if conditional the joint works, but, obviously, without restriction. Any idea?

Luca Angeletti
  • 58,465
  • 13
  • 121
  • 148
  • What result are you getting for the boundingBox call? Is it the same as what you were getting before? Do you source control your work? – Allen S Jun 16 '14 at 22:11
  • How can I get that? I put two NSLog's, one in the touchBegan function and other in the conditional function, and this second one doesn't appear in the log dialog... – user3739270 Jun 17 '14 at 01:27
  • Yes you can NSLog the bounding box or just set a break point there and step one passed it and examine it's value. Does the previous version of your app and the current version have different values for the bounding box? Also looking at the bounding box now, does it look valid? As for source control that is something all programmers should be doing and if you don't know anything about it then that means you haven't been doing it. – Allen S Jun 17 '14 at 16:46
  • Well, I figured out that it was something about the bounding box, but I didn't know what was exactly. So I decided to return to SpriteBuilder 1.0 and Cocos2D v3.0... Thanks for your help! – user3739270 Jun 18 '14 at 17:54
  • Another thing you can try is to calculate the bounding box manually and see if that works. If it does then you know something is not being set correctly in v3.1 with the bounding box. The bounding box is the lower-left of the object as the CGRect's origin and the rect's size is the width and height of the object. So for a sprite you can calculate the lower left as (using the position's X as an example in pseudo-ish code) position.x = position.x - (sprite.width * scale.x * anchor.x). The y is the same of course with the exception of using the y values and height. – Allen S Jun 18 '14 at 18:52

0 Answers0