rickylai
rickylai

Reputation: 59

Changing Label/Sprite in CCMenu

I'm new to Cocos2D and ran into a problem when I'm trying to implement a CCMenu. I am wondering how to change the label/sprite in the CCMenu after it is added to the layer. The code below is what I've tried so far.

CGSize screenSize = [CCDirector sharedDirector].winSize;

    CCLabelTTF *label1 = [CCLabelTTF labelWithString:@"HELLO!!!" fontName:@"Arial" fontSize:20];
    CCLabelTTF *label2 = [CCLabelTTF labelWithString:@"BYE!!!" fontName:@"Arial" fontSize:20];
    CCMenuItemLabel *labelItem1 = [CCMenuItemLabel itemWithLabel:label1];
    [labelItem1 setTag:111];
    CCMenu *menu = [CCMenu menuWithItems:labelItem1, nil];

    [self addChild:menu];
    [menu setPosition:ccp(screenSize.width/2, screenSize.height/2)];
    [(CCMenuItemLabel*)[labelItem1 getChildByTag:111] setLabel:label2];

I can't figure out why the screen is still showing "HELLO!!" instead of "BYE!!!". Please help me out. I would really appreciate for your help.

Upvotes: 1

Views: 877

Answers (1)

YvesLeBorg
YvesLeBorg

Reputation: 9079

hmmm the way I read this, labelItem1 is a child of menu. Try

 [(CCMenuItemLabel*)[menu getChildByTag:111] setLabel:label2];

Upvotes: 1

Related Questions