Square collision detection problem (iPhone).

Posted by thyrgle on Stack Overflow See other posts from Stack Overflow or by thyrgle
Published on 2010-05-22T04:17:05Z Indexed on 2010/05/22 4:20 UTC
Read the original article Hit count: 156

Hi, I know I've probably posted three questions related to this then deleted them, but thats only because I solved them before I got an answer. But, this one I can not solve and I don't believe it is that hard compared to the others. So, with out further ado, here is my problem:

So I am using Cocos2d and one of the major problem is they don't have buttons. To compensate for there lack in buttons I am trying to detect if when a touch ended did it collide with a square (the button). Here is my code:

- (void)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:touch.view];
    NSLog(@"%f", 240-location.y);
    if (isReady == YES)
    {
        if (((240-location.y) <= (240-StartButton.position.x - 100) || -(240-location.y) >= (240-StartButton.position.x) + 100) && ((160-location.x) <= (160-StartButton.position.y) - 25 || (160-location.x) >= (160-StartButton.position.y) + 25))
        {
            NSLog(@"Coll:%f", 240-StartButton.position.x);
            CCScene *scene = [PlayScene node];
            [[CCDirector sharedDirector] replaceScene:[CCZoomFlipAngularTransition transitionWithDuration:2.0f scene:scene orientation:kOrientationRightOver]];
        }
    }
}

Do you know what I am doing wrong?

© Stack Overflow or respective owner

Related posts about cocos2d

Related posts about iphone