Sunday, September 9, 2012

cocos2d Expand CCMenuItem Touch Area

If you ever wanted to expand the touch area of a CCMenuItem just expand the contentSize property.  If you have a CCMenuItemSprite or CCMenuItemImage the CCSprite will show in the bottom left corner.  if  you wanted the CCSprite to show in the middle right portion of the contentSize you can do some code like this:


CCMenuItemSprite* nextButton;
...


    nextButton.contentSize = CGSizeMake(nextButton.boundingBox.size.width + 1000, nextButton.boundingBox.size.height);
    [[[nextButton children] objectAtIndex:0] setAnchorPoint:ccp(1,0.5)];
    [[[nextButton children] objectAtIndex:1] setAnchorPoint:ccp(1,0.5)];
    [[[nextButton children] objectAtIndex:0] setPosition:ccp(nextButton.contentSize.width, nextButton.contentSize.height/2)];
    [[[nextButton children] objectAtIndex:1] setPosition:ccp(nextButton.contentSize.width, nextButton.contentSize.height/2)];

source: http://stackoverflow.com/questions/5622390/cocos2d-extend-touch-area-from-a-button
keywords: ccmenuitem bigger contentsize

No comments:

Post a Comment