当我尝试在iTouch 5上构建并运行我的游戏(基于Cocos2d 1.0.1,内置于iOS 6.0 SDK的Xcode 4.5)时,我发现CCMenuItems表现不正常:当menuitem与屏幕边缘相邻时,边缘边缘似乎不是那么容易被轻拍内部响应触摸事件(抱歉我的表情很差)。
为了演示这个问题,我使用Cocos2d模板编写了一个带有Xcode 4.3的演示应用程序,只是修改了HelloWorldLayer的init方法,现象仍然存在。代码如下:
-(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;
}
我在互联网上看了一眼,没有运气,不知道有人可以帮助我。非常感谢!
答案 0 :(得分:2)
只需几次预备:
如果要自由定位菜单项,请确保将每个菜单项包装在CCMenu节点中。然后,您可以通过菜单定位项目。