FreeFire
FreeFire

Reputation: 169

Having problems with cocos2d and menus?

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.

Upvotes: 0

Views: 159

Answers (3)

Kirit Modi
Kirit Modi

Reputation: 23407

You have to set Position of CCMenu in your code as below

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{}

Upvotes: 1

Abhineet Prasad
Abhineet Prasad

Reputation: 1271

Merely copying the file from initial directory to the Resources folder in your Xcode project wouldnt work. You need to add it to your bundle resources. For that,

Drag the picture from your project's Resources folder and drop under the Resources folder on the Project navigator bar in xcode (on the left side). Make sure to check "Add to Target"

Upvotes: 0

Guru
Guru

Reputation: 22042

Try this once:

    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

Still not work, then put break point and confirm sprite is not nil.

Upvotes: 0

Related Questions