我在 Mac 上玩 Cocos2D。
我正在使用带有 NSColorWell 按钮的 IntefaceBuilder。我的 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];
}
动画层.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]];
}