I m 试图通过像这样的国家安全通知发出一个CGPoint
-(void)setPosition:(CGPoint)point
{
NSString *pointString = NSStringFromCGPoint(point);
NSDictionary *dict = [[NSDictionary alloc]
initWithObjectsAndKeys:@"p", pointString, nil];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"BownceSpriteDidSetPosition"
object:self
userInfo:dict];
[super setPosition:CGPointMake(point.x, point.y)];
}
我已照此办理了观察员。
-(void) init
{
if((self = [self init])){
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(setViewPointCenter:)
name:@"BownceSpriteDidSetPosition"
object:nil];
// I wondered wether object should be something else???
// more code etc....
}
return self
}
-(void) setViewPointCenter:(NSNotification *)notification
{
NSString * val = [[notification userInfo] objectForKey:@"p"];
CGPoint point = CGPointFromString(val);
// trying to debug
NSString debugString = [NSString stringWithFormat:@"YPOS -----> %f", point.y];
NSLog(debugString);
CGPoint centerPoint = ccp(240, 160);
viewPoint = ccpSub(centerPoint, point);
self.position = viewPoint;
}
但看来,CG Point是空的,或(0,0)可能是空的。 无论是哪种方式,它都不会产生预期的效果,而辩论显示的是点。
从我发现的所有例子来看,我喜欢我这样做。 但显然我不是这样。 谁能把我推向正确的方向,指出我的错误?