I use cocos2D for iphone.
I have 3 scenes: scene A,scene B, and scene C
- in scene C, click to open scene A, but scene A is not opened yet;
- open scene B first, scene B has many buttons
- users click a button on scene B, then scene B dismisses and returns a value v to scene C;
- according to value v, scene C decides to open or not open scene A;
All I need is a callback function, I use delegate to accomplish this successfully.
I have a protocol:
@protocol SceneBDelegate <NSObject>
@required
- (void)dismissWithValue:(BOOL)value;
@end
In scene B, when a button is clicked:
-(void) clickBtn{
if([self.delegate respondsToSelector:@selector(dismissWithValue:)]){
[self.delegate dismissWithValue: YES];
}
[self removeFromParent];
}
In scene C,
-(void) dismissWithValue:(BOOL)value{
if(value){
// do something;
}
}
These codes work well, but I want to know how to accomplish this with block?
I have readed about Jens Ayton's post is this question, how-to-perform-callbacks-in-objective-c
He explains how to use block, but I can't figure out how to connect users' action with block.
I konw UIViewController has a I found when using UIViewController has a function:
(void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^)(void))completion NS_AVAILABLE_IOS(5_0);
it supports block.
But I use cocos2D, I didn't find a similar funciton.
Can anyone give me some advices? Thanks a lot!