Why do touches only get detected ABOVE my CCBitmapFontAtlas and not ON it? (cocos2d)

Posted by RexOnRoids on Stack Overflow See other posts from Stack Overflow or by RexOnRoids
Published on 2010-05-23T08:05:29Z Indexed on 2010/05/23 8:10 UTC
Read the original article Hit count: 195

I am detecting touches for CCBitmapFontAtlas (just text labels) as shown in the code below. But it seems that touches are only detected slightly ABOVE the CCBitmapFontAtlases? Did something get screwed when converting between coordinate systems?

(*Note objects label1, label2, etc are CCBitmapFontAtlas)

- (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;

        CGRect rectLabel1 = CGRectMake(label1.position.x, label1.position.y, label1.contentSize.width, label1.contentSize.height);
        CGRect rectLabel2 = CGRectMake(label2.position.x, label2.position.y, label2.contentSize.width, label2.contentSize.height);
        CGRect rectLabel3 = CGRectMake(label3.position.x, label3.position.y, label3.contentSize.width, label3.contentSize.height);
        CGRect rectLabel4 = CGRectMake(label4.position.x, label4.position.y, label4.contentSize.width, label4.contentSize.height);
        CGRect rectLabel5 = CGRectMake(label5.position.x, label5.position.y, label5.contentSize.width, label5.contentSize.height);
        CGRect rectLabel6 = CGRectMake(label6.position.x, label6.position.y, label6.contentSize.width, label6.contentSize.height);


        if(CGRectContainsPoint(rectLabel1, location)){

            NSLog(@"Label 1 Touched");

        }else if(CGRectContainsPoint(rectLabel2, location)){

            NSLog(@"Label 2 Touched");

        }else if(CGRectContainsPoint(rectLabel3, location)){

            NSLog(@"Label 3 Touched");

        }else if(CGRectContainsPoint(rectLabel4, location)){

            NSLog(@"Label 4 Touched");

        }else if(CGRectContainsPoint(rectLabel5, location)){

            NSLog(@"Label 5 Touched");

        }else if(CGRectContainsPoint(rectLabel6, location)){

            NSLog(@"Label 6 Touched");

        }

    }
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode