0

I'm using the Cocosbutton class to create a button which is added to the scene. This creates a CCSprite which is added to a CCMenuItem inside a CCMenu:

@interface CocosButtonItem : CCMenuItem {
...

In the init method, the background is added:

        UIImage *bgImage = [UIImage imageWithContentsOfFile:@"buttonback.png"],
        back = [CCSprite spriteWithCGImage:bgImage.CGImage key:@"bgimage"];
        back.anchorPoint = ccp(0,0);
        self.contentSize = back.contentSize;

        CCLayerColor *bgFill = [CCLayerColor layerWithColor:ccc4(255.0, 255.0, 255.0, 255.0)];
        bgFill.contentSize = self.contentSize;
        bgFill.position = ccp(0,0);
        [self addChild:bgFill];

        back.color = ccc3(255,255,255);
        [self addChild:back]; // without this, I just get a whit layer (as intended)

Once I add that final line to add the sprite to the CCMenuItem, I get a black background (see screenshot). The source for the CCSprite background image is an 8bit .png with transparency, and I can't figure out why I'm seeing this black background.

Black background around a CCSprite in a CCMenuItem

Echilon
  • 10,064
  • 33
  • 131
  • 217
  • Have you tried using the CCMenuItemImage and the CCMenu? – Yannick Loriot Sep 06 '12 at 08:37
  • Thanks for the tip. I tried CCMeniItemImage but I still got the black background. Oddly though, if I just do `CCLayerColor *bgFill = [CCLayerColor layerWithColor:ccc4(255.0, 255.0, 255.0, 255.0)]; bgFill.contentSize = self.contentSize; bgFill.position = ccp(0,0); [self addChild:bgFill z:-1];` I get a white rectangle and neither a label nor background images. – Echilon Sep 15 '12 at 11:18

0 Answers0