ioscocos2d-iphoneios6iphone-5ccmenuitem

Touch accuracy of ccmenuitem is lower when it is placed adjacent to screen edge


When I tried to build and run my game(based on Cocos2d 1.0.1, built in Xcode 4.5 with iOS 6.0 SDK) on iTouch 5, I found the CCMenuItems do not behave normally: when the menuitem is adjacent to screen edge, the edge border seems not so easy to be tapped inside to respond the touch event(Sorry for my poor expression).

To demonstrate the problem, I wrote a demo app with Xcode 4.3 using Cocos2d template and just modify the HelloWorldLayer's init method, and the phenomenon still happens. The code is below:

    -(void) init
    {
            // always call "super" init
            // Apple recommends to re-assign "self" with the "super" return value
            if( (self=[super init])) {

            CCLayerColor *cl = [CCLayerColor layerWithColor:ccc4(ccWHITE.r, ccWHITE.g, ccWHITE.b, 255)];
            [self addChild:cl];
                    // create and initialize a Label
                    CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];

                    // ask director the the window size
                    CGSize size = [[CCDirector sharedDirector] winSize];

                    // position the label on the center of the screen
                    label.position =  ccp( size.width /2 , size.height/2 );

                    // add the label as a child to this Layer
                    [self addChild: label];

                    float width = 160;

                    CCSprite *sp1 = [CCSprite node];
                    [sp1 setContentSize:CGSizeMake(width, width)];
                    [sp1 setTextureRect:CGRectMake(0, 0, width, width)];
                    [sp1 setColor:ccc3(0xff, 0xff, 0)];

                    CCSprite *sp2 = [CCSprite node];
                    [sp2 setContentSize:CGSizeMake(width, width)];
                    [sp2 setTextureRect:CGRectMake(0, 0, width, width)];
                    [sp2 setColor:ccc3(0, 0, 0xff)];

                    CCMenuItemSprite *button = [CCMenuItemSprite itemFromNormalSprite:sp1 selectedSprite:sp2 target:nil selector:nil];
                    CCMenu *menu = [CCMenu menuWithItems:button, nil];
                    [self addChild:menu];
                    menu.position = ccp(0, 0);
                    button.anchorPoint = ccp(1, 1);
                    button.position = ccp([[CCDirector sharedDirector] winSize].width,
                                  [[CCDirector sharedDirector] winSize].height);


            }
            return self;
    }

I looked all over the internet and had no luck, wonder someone can help me with that. Many Thanks!


Solution

  • Just a few hunches:

    If you want to freely position your menu items, make sure to wrap each in a CCMenu node. Then you can position the item via the menu.