0

I have a class ButtonLayer with a method in it called redClick. redClick's implementation looks like this..

-(void) redClick {
    [red runAction: [CCTintTo actionWithDuration:0.1 red:200 green:200 blue:200]];
}

The variable red is a CCSprite in the ButtonLayer class.

I have another class called MainLayer that inherits from CCLayer. The scene method in this class looks like this..

+(CCScene *) scene
{
    CCScene *scene = [CCScene node];

    overlay = [ButtonLayer node];
    HelloWorldLayer *layer = [HelloWorldLayer node];

    [scene addChild: layer];
    [scene addChild: overlay];

    return scene;
}

In my ccTouchesBegan method in MainLayer, I call [overlay redClick], but when I call it, nothing changes. The CCSprite remains unchanged.

1 Answers1

0

Add overlay layer to your HelloWorldLayer 'layer'.

+(CCScene *) scene
{
    CCScene *scene = [CCScene node];

    overlay = [ButtonLayer node];
    HelloWorldLayer *layer = [HelloWorldLayer node];

    [scene addChild: layer];
    [layer addChild: overlay];

    return scene;
}
Guru
  • 21,652
  • 10
  • 63
  • 102
  • I got it to work by making the redClick method a class method and calling [ButtonLayer redClick]. I've used this after adding overlay to both the HelloWorldLayer and the scene and it works either way. Simply adding it to the layer as above though without the class method conversion doesn't work. Not sure why.. – user1371455 Jul 19 '12 at 20:08