1

我们可以检查CGPoint是否已经触及CMenu项目吗?如果点在按钮中,我需要返回 YES,如果点不在按钮中,我需要返回 NO。

 -(BOOL)isButton:(CGPoint)point
    {
        if(controlMode == 1)
        {

            for (CCMenu *menu in self.children)
            {

                    // If point in button
                    return YES;
                    // else
                    return NO;


                }
            }

        }
        return NO;
    }

菜单按钮:

CCMenuItem *pauseItem = [CCMenuItemImage itemFromNormalImage:@"pause.png" selectedImage:@"pause_.png" target:self selector:@selector(pauseGame:)]; 
CCMenuItem *resetItem = [CCMenuItemImage itemFromNormalImage:@"reset.png" selectedImage:@"reset_.png" target:self selector:@selector(resetClicked:)]; 
CCMenu *Menu = [CCMenu menuWithItems:pauseItem,resetItem, nil];
Menu.position = ccp(450, 40); 
[Menu alignItemsVerticallyWithPadding:5]; 
[self addChild:Menu];
4

2 回答 2

2

由于您所指的点是触摸(来自评论),因此如果您正在触摸菜单上的按钮,则会选择该项目。

-(BOOL) isAButtonSelected
{
    for(CCMenuItem* item in menu.children)
    {
        if(item.isSelected) return YES;
    }
    return NO;
}
于 2012-04-14T10:28:54.797 回答
1

你可以这样尝试

for(CCMenuItem* item in yourMenu.children)
{
    CCPoint localPoint = [item convertToNodeSpace:point];
    if( (localPoint.x <= item.contentSize.width) && (localPoint.y <= item.contentSize.height) )
    {
        // in that case your point is in this item of your CCMenu
    }
}
于 2012-04-11T22:20:12.423 回答