Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch Location #4

Open
romeouald opened this issue Apr 11, 2012 · 0 comments
Open

Touch Location #4

romeouald opened this issue Apr 11, 2012 · 0 comments

Comments

@romeouald
Copy link

Hi!

I implemented your solution in an iPad app, where only one part of the screen was the scroll view. This way the overridden "-(CCMenuItem *) itemForTouch: (UITouch *) touch" wasn't working right. I came up with an updated function, that suits this more commonly (maybe should be used this way in cocos framework, idk.), even with more menus on one screen, one on the scroll view, one on the "static" view:

-(CCMenuItem *) itemForTouch: (UITouch *) touch
{
CGPoint touchLocation = [touch locationInView:[[CCDirector sharedDirector] openGLView]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];

CCMenuItem* item;
CCARRAY_FOREACH(children_, item){
    // ignore invisible and disabled items: issue #779, #866
    if ([item visible] && [item isEnabled] ) {
        CGRect itemRect = CGRectMake([item convertToWorldSpace:CGPointZero].x, [item convertToWorldSpace:CGPointZero].y, item.contentSize.width, item.contentSize.height);
        if( CGRectContainsPoint(itemRect, touchLocation)) {
            return item;
        }
    }
}
return nil;

}

What do you think? Is this an improvement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant