How to tell if you touched a CCLabel? (Cocos2d Question)

Posted by RexOnRoids on Stack Overflow See other posts from Stack Overflow or by RexOnRoids
Published on 2010-05-23T06:27:40Z Indexed on 2010/05/23 6:30 UTC
Read the original article Hit count: 349

Filed under:
|
|
|

How to tell if you touched a CCLabel?

The following code obviously does not work well enough because it only tests for point equality. Naturally touch point will not necessarily be equal to the position property of the CCLabel (CCNode). How to I tell if a Touch point has fallen within the "rectangle?" of the CCLabel?

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    for( UITouch *touch in touches ) {
        CGPoint location = [touch locationInView: [touch view]];

        location = [[CCDirector sharedDirector] convertToGL:location];

        self.myGraphManager.isSliding = NO;

        if(CGPointEqualToPoint(location, label1.position)){

            NSLog(@"Label 1 Touched");

        }else if(CGPointEqualToPoint(location, label2.position)){

            NSLog(@"Label 2 Touched");

        }else if(CGPointEqualToPoint(location, label3.position)){

            NSLog(@"Label 3 Touched");

        }else if(CGPointEqualToPoint(location, label4.position)){

            NSLog(@"Label 4 Touched");

        }else if(CGPointEqualToPoint(location, label5.position)){

            NSLog(@"Label 5 Touched");

        }else if(CGPointEqualToPoint(location, label6.position)){

            NSLog(@"Label 6 Touched");

        }


        NSLog(@"Touch Made!");
    }
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode