我一直在为 iPhone 开发 cocos2d 应用程序。我一直在我的 iPhone 5 上测试它。一切看起来都很棒,但是当我在 3.5 英寸模拟器 iPhone 上测试它时,一些按钮丢失了,一些标签放错了位置。
我想知道为什么会这样?我原以为一切都通过 cocos2d 网格定位,然后将其转换为像素,因此无论屏幕大小如何,布局看起来都应该相同。
我认为问题的部分原因可能是当我设置菜单项的位置时,(0,0) 将它放在屏幕的中心。我不知道这是为什么。
关于发生了什么的任何建议?
左边是 iPhone 5,左边是模拟器(3.5 英寸)。
这是此屏幕的代码:
CCSprite *title = [CCSprite spriteWithSpriteFrameName:@"highscoresTitle.png"];
[self addChild:title];
title.position = ccp([CCDirector sharedDirector].winSize.width/2, [CCDirector sharedDirector].winSize.height-title.contentSize.height-15);
background.position = ccp([CCDirector sharedDirector].winSize.width/2, [CCDirector sharedDirector].winSize.height/2);
play = [CCMenuItemSprite itemWithNormalSprite:[CCSprite spriteWithSpriteFrameName:@"playNew.png"] selectedSprite:[CCSprite spriteWithSpriteFrameName:@"playNew.png"] target:self selector:@selector(playScene:)];
play.position = ccp(0, -200);
CCLabelTTF *backLabel = [CCLabelTTF labelWithString:@"BACK" fontName:@"RBNo2-Light-Alternative" fontSize:25];
CCMenuItemLabel *goBack = [CCMenuItemLabel itemWithLabel:backLabel target:self selector:@selector(back:)];
goBack.position = ccp(0, -260);
CCMenuItemSprite *gameicon = [CCMenuItemSprite itemWithNormalSprite:[CCSprite spriteWithSpriteFrameName:@"gameCenter.png"] selectedSprite:[CCSprite spriteWithSpriteFrameName:@"gameCenter.png"] target:self selector:@selector(gameIcon:)];
gameicon.position = ccp(0, -150);
CCMenu *menu = [CCMenu menuWithItems:play,goBack, gameicon, nil];
[self addChild:menu z:0];
for(int i = 0; i<5 && i<length; i++){
NSString *temp = [NSString stringWithFormat:@"%d: %d", i+1,[[highscores objectAtIndex:i]intValue]];
CCLabelTTF *label = [CCLabelTTF labelWithString:temp fontName:@"RBNo2-Light-Alternative" fontSize:20];
label.position = ccp([CCDirector sharedDirector].winSize.width/2, 350-i*30);
label.visible = YES;
[self addChild:label z:100 tag:1];
}
NSString *temp = [NSString stringWithFormat:@"Last Score: %d", newHighscore];
CCLabelTTF *label = [CCLabelTTF labelWithString:temp fontName:@"RBNo2-Light-Alternative" fontSize:20];
label.position = ccp([CCDirector sharedDirector].winSize.width/2, 415);
label.visible = YES;
[self addChild:label z:100 tag:1];
这是另一个带有滑块的示例:(iPhone 5 左)
这是滑块的代码:
sliderCtl = [[UISlider alloc]initWithFrame:CGRectMake(100, 460, 200, 0)];
//[sliderCtl.layer setAffineTransform:CGAffineTransformMakeRotation(3.141/2)];
[sliderCtl addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
sliderCtl.backgroundColor = [UIColor clearColor];
sliderCtl.value = 1.0;
[[[[CCDirector sharedDirector] openGLView] window] addSubview:sliderCtl];
sliderEff = [[UISlider alloc]initWithFrame:CGRectMake(100, 402, 200, 0)];
[sliderEff addTarget:self action:@selector(effectsSlider:) forControlEvents:UIControlEventValueChanged];
sliderEff.backgroundColor = [UIColor clearColor];
sliderEff.value = 1.0;
[[[[CCDirector sharedDirector] openGLView] window] addSubview:sliderEff];
非常感谢。