0
我似乎無法得到CCCallFuncO與actionWithTarget工作設置爲(JoinedMapsLayer *)self.parent的Cocos2D:CCCallFuncO與目標父
JoinedMapsLayer是一個精靈類被添加到父節點。
裏面的精靈類我有一個方法:
-(void) playAction:(NSString*)name withMessagePart:(NSString *)messagePart {
id displayMessageBox = [CCCallFuncO actionWithTarget:(JoinedMapsLayer*)self.parent
selector:@selector(displayMessageBox:)
object:[NSString stringWithFormat:messagePart]];
if([name isEqualToString:@"shiver"]){
id a1 = [CCMoveTo actionWithDuration:.05 position:ccp(self.sprite.position.x+2, self.sprite.position.y)];
id a2 = [CCMoveTo actionWithDuration:.05 position:ccp(self.sprite.position.x-4, self.sprite.position.y)];
id a3 = [CCMoveTo actionWithDuration:.05 position:ccp(self.sprite.position.x+4, self.sprite.position.y)];
id a4 = [CCMoveTo actionWithDuration:.05 position:ccp(self.sprite.position.x-2, self.sprite.position.y)];
[self.sprite runAction:[CCSequence actions:a1,a2,a3,a2,a3,a2,a3,a2,a3,a2,a3,a2,a3,a2,a3,a2,a3,a2,a3,a2,a3,a2,a3,a4,displayMessageBox, nil]];
}
else if([name isEqualToString:@"spin"]){
id a1 = [CCRotateBy actionWithDuration:.5 angle:360];
[self.sprite runAction:[CCSequence actions:a1,displayMessageBox, nil]];
}
}
它運行的操作上的精靈就好了,但我的努力得到它來調用父節點的方法。我有一個NSLog在那裏檢查,沒有任何反應。任何明顯的原因爲什麼
在我父節點的init類被添加到一個可變數組
HummingClass *hummingChar = [[HummingClass alloc] init];
[characterArr addObject:hummingChar]
而且後來我訪問類的,如:
HummingClass *hummingChar = [characterArr objectAtIndex:interactionIndex];
有趣的是,它不崩潰self.parent,所以我想我沒有正確指向父節點。在對象頭我有
#import "JoinedMapsLayer.h"
@class JoinedMapsLayer
編輯:即便我做了這樣一個普通的方法調用,它不會工作:
[(JoinedMapsLayer*)self.parent displayMessageBox:@"whatever"];