i’ve got my code in HelloWorldLayer, i’m using a delegate to change the score number in ScoreLayer, and i would like to send a message back from ScoreLayer to HelloWorldLayer, in order to change the ui with a new image.
Is it ok to create a delegate in each class (one delegate of HelloW… in ScoreLayer, and one delegate of ScoreLayer in HelloW…) ? Something like that :
hellolayer.delegate = scoreLayer;
scoreLayer.powerUpDelegate = hellolayer;
?
@class MyClass does not work : the protocols are not being recognized.
"#import "..." : one of the protocol is not recognized, but i guess there will be a problem, as classA will import classB, which will import classA again etc.
How should i do? Here’s some of the code :
//in HelloWorldLayer.h :
#import "ScoreLayer.h"
@protocol PowerUpDelegate
-(void)scalePowerUp;
@end
// HelloWorldLayer
@interface HelloWorldLayer : CCLayer <PowerUpDelegate>
{ … }
@property (nonatomic,retain) id <ScoreDelegate> delegate;
//in ScoreLayer.h :
//@class HelloWorldLayer; -->does not recognize the protocol
#import "HelloWorldLayer.h"
@protocol ScoreDelegate
//...
@end
@interface ScoreLayer : CCLayer <ScoreDelegate>{
//...
}
@property (nonatomic,retain) id <PowerUpDelegate> powerUpDelegate;//-->cannot find protocol definition...
Thanks
I recommend using a third class which implements both protocols and use that class to handle the delegate methods.