代码之家  ›  专栏  ›  技术社区  ›  Martin

更改cocos2d标签上的颜色

  •  0
  • Martin  · 技术社区  · 15 年前

    我有一个可变的CCLabel数组。创建标签阵列时,我使用以下方法将标签颜色设置为黑色:

    label.color = ccc3(0,0,0);
    

    在不同的点,我想改变一个给定标签的颜色。

        -(void)updateLabel:(CCLabel*)l{
            [l setColor: ccc3(1.0,1.0,0.0)];
      }
    

    我知道我有一个指向标签的有效指针,因为如果我将方法更改为

    [l setString:@"test"];
    

    它可以正确地更改标签。但是颜色没有改变。我在文档中没有看到任何东西表明颜色设置后是不变的。有人知道会发生什么吗?

    3 回复  |  直到 15 年前
        1
  •  1
  •   Nixarn    13 年前

    它不接受浮点数,而是接受字节值。因此,以下措施将起作用:

    label.color = ccc3(255, 255, 0); 
    
    or 
    
    [label setColor: ccc3(255, 255, 0)];
    
        2
  •  0
  •   Jacob Relkin    15 年前

    CCLabel 的超类, CCSprite ,您将看到:

    线 144 : http://www.cocos2d-iphone.org/api-ref/0.99.0/_c_c_sprite_8h_source.html

    这意味着一旦创建了对象,就不能设置 color ,它是严格只读的。

        3
  •  -1
  •   Renish Dadhaniya    12 年前
    //create Label like this
    CCLabelBMFont *lblInfo = [CCLabelBMFont labelWithString:@"Multi Color Label" fntFile:@"SSPro.fnt"];
    
    then, you can Access the character using Index path.
    
      for (i=starting index; i<ending index; i ++) {
    
            CCSprite *charSprite = (CCSprite *)[[lblInfo children] objectAtIndex:i];
            charSprite.color = [CCColor redColor];
        }
    set or change the color of character.
    
    推荐文章