gpt4 book ai didi

iphone - COCOS 2d V2.x 菜单对齐问题 - 在 iPhone Simulator 5.1 和 iPhone 4 设备上测试

转载 作者:行者123 更新时间:2023-11-29 11:08:54 26 4
gpt4 key购买 nike

不确定为什么菜单与左上角对齐,以前的版本菜单与中心完美对齐。在 iPhone 4 中测试。

我知道解决方案 [menu setPosition:ccp( size.width/2, size.height/2)]; 但想了解为什么它与左上角对齐。

要获得相同的结果,请在 AppDelegate 中尝试此操作

[director_ pushScene: [HelloWorldLayer scene]]; 

代替

[director_ pushScene: [IntroLayer scene]];

我的结果和我的代码

enter image description here

更新源

菜单层.h

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface MenuLayer : CCLayer {

}

+(CCScene *) scene;

@end

MenuLayer.m

#import "MenuLayer.h"


@implementation MenuLayer

+(CCScene *) scene
{
CCScene *scene = [CCScene node];

MenuLayer *layer = [MenuLayer node];

[scene addChild: layer];

return scene;
}

-(id) init
{
if( (self=[super init]) ) {
CCMenuItem *itemAchievement = [CCMenuItemFont itemWithString:@"Play" block:^(id sender) {}];
CCMenuItem *itemLeaderboard = [CCMenuItemFont itemWithString:@"Settings" block:^(id sender) {}];

CCMenu *menu = [CCMenu menuWithItems:itemAchievement, itemLeaderboard, nil];

[menu alignItemsVertically];

[self addChild:menu];
}
return self;
}
@end

AppDelegate.m

    [director_ pushScene: [MenuLayer scene]];

最佳答案

好吧,我先告诉你答案:

你出了点问题 :) ..你一定是改变了 parent 的位置,或者它的祖 parent ,......等等。

编辑:

您的错误是在此方法中运行 CCDirector:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

...
// Remove this code !
[director_ runWithScene:blah];
}

相反,您必须像这样运行 CCDirector:

// This method is part of the CCDirectorDelegate methods
// Add it below the - (BOOL)application: didFinishLaunchingWithOptions:
-(void) directorDidReshapeProjection:(CCDirector*)director
{
if(director.runningScene == nil) {
// Add the first scene to the stack. The director will draw it immediately into the framebuffer. (Animation is started automatically when the view is displayed.)
// and add the scene to the stack. The director will run it when it automatically when the view is displayed.
[director_ runWithScene: [HelloWorldLayer scene]];
}
}

证据:

阅读 cocos2d 文档!他们说,如果您在 iOS 6 之前的 iOS 版本上运行,则不得在 application: didFinishLaunching: 方法中运行 CCDirector

来自文档:

This is needed for iOS4 and iOS5 in order to ensure that the 1st scene has the correct dimensions This is not needed on iOS6 and could be added to the application:didFinish...

这是你的照片,经过剖析:

enter image description here

那真是一团糟……cocos2d 的默认行为不可能是那样的。新建cocos2d v2.x,清理HelloWorldLayer.m,结果如下:

// Achievement Menu Item using blocks
CCMenuItem *itemAchievement = [CCMenuItemFont itemWithString:@"Achievements" block:^(id sender) {}];
// Leaderboard Menu Item using blocks
CCMenuItem *itemLeaderboard = [CCMenuItemFont itemWithString:@"Leaderboard" block:^(id sender) {}];

CCMenu *menu = [CCMenu menuWithItems:itemAchievement, itemLeaderboard, nil];

[menu alignItemsVertically];

[self addChild:menu];

enter image description here

关于iphone - COCOS 2d V2.x 菜单对齐问题 - 在 iPhone Simulator 5.1 和 iPhone 4 设备上测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12439654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com