0

I'm having a problem with xcode when making a menu when using the cocos2d templates. I put this code in:

if( (self=[super init]) ) {
    CCMenuItemImage *item = [CCMenuItemImage itemWithNormalImage:@"bug.png" selectedImage:@"bug.png" target:self selector:@selector(doThis:)];
    CCMenu *menu = [CCMenu menuWithItems:item, nil];
    [self addChild:menu];
}
return self;
-(void)doThis:(id)sender{}

I put the if statement in the -(id) init method in helloworldlayer.m. If anyone can help that would be greatly appreciated. I'm having the problem where everything builds correctly, but the picture doesn't show. I have it copied to my resources, but when I build it, no picture is shown.

4

3 回答 3

1

您必须在代码中设置 CCMenu 的位置,如下所示

if( (self=[super init]) ) {
    CCMenuItemImage *item = [CCMenuItemImage itemWithxNormalImage:@"bug.png" selectedImage:@"bug.png" target:self selector:@selector(doThis:)];
    CCMenu *menu = [CCMenu menuWithItems:item, nil];
    menu.position = ccp(200,200);
    [self addChild:menu];
}
return self;
-(void)doThis:(id)sender{}
于 2013-10-03T05:08:40.173 回答
0

试试这个:

    CCSprite *sprite_1 = [CCSprite spriteWithFile:@"bug.png"];
    CCSprite *sprite_2 = [CCSprite spriteWithFile:@"bug.png"];

    CCMenuItemSprite * item = [CCMenuItemSprite itemWithNormalSprite:close_1
                                      selectedSprite:close_2
                                              target:self
                                            selector:@selector(doThis:) ];
     CCMenu *menu = [CCMenu menuWithItems:item, nil];
     [self addChild:menu];

     item.position = ccp(200,200); //Set position

仍然不行,然后放断点并确认精灵不是零。

于 2013-10-03T02:49:41.397 回答
0

仅仅将文件从初始目录复制到 Xcode 项目中的 Resources 文件夹是行不通的。您需要将其添加到您的捆绑资源中。为了那个原因,

将图片从项目的 Resources 文件夹中拖放到 xcode 中 Project navigator 栏上的 Resources 文件夹下(在左侧)。确保选中“添加到目标

于 2013-10-03T04:33:18.120 回答