开发者

how to underline/change color menu item?

开发者 https://www.devze.com 2023-02-04 14:36 出处:网络
i am using this code to create menu and menu items .What i want to do is when i click anymenu item it should be underlined showing that my current selection is this or is changes color ...

i am using this code to create menu and menu items .What i want to do is when i click anymenu item it should be underlined showing that my current selection is this or is changes color ...

My code..

CCMenuItem *AutoFire1 = [CCMenuItemFont itemFromString:@"Auto" target:self selector:@selector(AutoFire:)];

    CCMenu *menu = [CCMenu menuWithItems:AutoFire1, nil];
    menu.position = ccp(170, 100);

//  [menu alignItemsVerticallyWithPadding:10];

    [self addChild:menu];


    CCMenuItem *MaunualFire1 = [CCMenuItemFont itemFromString:@"Maunal" target:self selector:@selector(MaunalFire:)];

    CCMenu *menu2 = [CCMenu menuWithItems:MaunualFire1, nil];
    menu2.position = ccp(300, 100);

    //  [menu alignItemsVerticallyWithPadding:10];

    [self addChild:menu2];

and the function that runs on touch here are...

  -(void) AutoFire: (id) sender 
    {
AutoFire=1; //Underline menuitem or change color to show current selection.开发者_运维问答..
     }
     -(void) MaunalFire: (id) sender
    {
AutoFire=0;
}

Help


Make CCMenuItem *AutoFire1 and CCMenuItem *MaunualFire1 instance variables of your layer.

In your method for when they are pressed, alter them accordingly to do what you want them to do.

I can't remember of the top of my head what the code is to change the colour of a CCMenuItemFont but you'd do something along the lines of

   -(void) AutoFire: (id) sender 
    {
    AutoFire=1;
    AutoFire1.color = ccc3(r,g,b);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消