CCLabelBMFont用于菜单项?

时间:2011-02-22 22:34:12

标签: cocos2d-iphone

嘿,我疯了,坚持这个。我想使用我的酷heiro字体表我得到CCLabelBMFont作为标签和得分变量工作很好,但无法将它们作为可点击项目进入菜单!但它CCLabelMBFont特别说明你可以将它们用作菜单项 - 见这里:

  

详细说明

CCLabelBMFont是CCSpriteBatchNode的子类

特点:

* Treats each character like a CCSprite. This means that each individual character can be:
      o rotated
      o scaled
      o translated
      o tinted
      o chage the opacity
* It can be used as part of a menu item.
* anchorPoint can be used to align the "label"
* Supports AngelCode text format
  

然而,我已经浏览了整个网络,找不到任何人将CCLabelBMFont作为菜单项的示例。这是我到目前为止的代码:

- (id)init {     if((self = [super init])){

    CCLabelBMFont *homeTest = [CCLabelBMFont labelWithString:@"HomeTEST" fntFile:@"hieroTitle2.fnt"];
    homeTest.position = ccp(0, 0);
    //finalScoreFont.position = ccp(wrapper.position.x, wrapper.position.y-40);
    [self addChild:homeTest z:2 tag:kTagHomeTest];

    /* here's where I am lost and want to put the CCLabelBMFont
    CCMenuItem *homeButton = 
    home.position = ccp(0, 0);

    CCMenu *menu = [CCMenu menuWithItems:homeButton, nil];
    menu.position = ccp(60, 50);
    */

    [self addChild:menu z:3];

}
return self;

}

1 个答案:

答案 0 :(得分:3)

我发现了一条线索和可能的解决方案!看看这个人的代码:

CCLabelBMFont *tlabel = [CCLabelBMFont labelWithString:@"Page 2" fntFile:@"customfont.fnt"];
CCMenuItemLabel *titem = [CCMenuItemLabel itemWithLabel:tlabel target:self selector:@selector(testCallback:)];
CCMenu *menu = [CCMenu menuWithItems: titem, nil];
menu.position = ccp(screenSize.width/2, screenSize.height/2);

尼斯!他首先制作标签,然后使用CCLabelBMFont作为CCMenuItemLabel Weeee!我从来没有想过这一点。我要去试试