Ich versuche, einen CGPoint über eine NSNotification wie folgt zu senden
-(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)];
}
Und ich habe den Beobachter wie folgt implementiert
-(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;
}
Aber es scheint, dass CGPoint leer ist, oder (0,0) vielleicht. So oder so, es ist nicht mit dem gewünschten Effekt, und die debugString zeigt point.y 0,0 sein.
Nach all den Beispielen, die ich gefunden habe, sieht es für mich so aus, als ob ich alles richtig machen würde. Aber offensichtlich tue ich das nicht. Kann mir jemand einen Schubs in die richtige Richtung geben und mich auf meinen Fehler hinweisen?