我在Mac上玩Cocos2D。來自Cocos2D的調用方法
我正在使用IntefaceBuilder和NSColorWell按鈕。我的AppDelegate具有IBAction,可以在一個名爲Settings的Singleton中設置背景顏色。然後我想讓它調用AnimationLayer的方法updateBackgroundColor
來更新它。但它失敗並崩潰。
爲什麼我不能讓消息AnimationLayer方法?
由於AppDelegate中已經知道AnimationLayer不是這個調用方法的正確方法? [(AnimationLayer*) self methodNameHere];
AppDeletgate.m
- (IBAction)colorwellBackground:(id)sender {
[mySettings setBackgroundColor:[sender color]];
[(AnimationLayer*) self updateBackgroundColor];
}
AnimationLayer.m
// Import the interfaces
#import "AnimationLayer.h"
// HelloWorldLayer implementation
@implementation AnimationLayer
+(CCScene *) scene {
CCScene *scene = [CCScene node];
AnimationLayer *layer = [AnimationLayer node];
[scene addChild: layer];
return scene;
}
// on "init" you need to initialize your instance
-(id) init {
if((self=[super init])) {
mySettings = [Settings sharedSettings];
//DEFAULT BACKGROUND COLOR
_backgroundColorLayer = [mySettings returnBackgroundColor];
[self addChild:_backgroundColorLayer];
}
return self;
}
- (void) updateBackgroundColor{
NSLog(@"UPDATE BACKGROUND COLOR %@", [mySettings returnBackgroundColor]);
[_backgroundColorLayer setColor:[mySettings returnBackgroundColor]];
}