当调用 CCMenuItemSprite 的“selected”方法时,我想调用目标选择器(见下文:buttonPressedWithId :)。
CCMenuItemSprite *buttonB = [CCMenuItemSprite itemWithNormalSprite:[CCSprite spriteWithSpriteFrameName:@"emptyCircle.png"] selectedSprite:[CCSprite spriteWithSpriteFrameName:@"greenCircle.png"] target:self selector:@selector(buttonPressedWithId:)];
我查看了 CCMenuItemSprite 的实现,发现了这个:
-(void) selected
{
[super selected];
//HERE IS WHERE I WANT TO CALL buttonPressedWithId:
if( selectedImage_ ) {
[normalImage_ setVisible:NO];
[selectedImage_ setVisible:YES];
[disabledImage_ setVisible:NO];
} else { // there is not selected image
[normalImage_ setVisible:YES];
[selectedImage_ setVisible:NO];
[disabledImage_ setVisible:NO];
}
}
目标是在 selected 方法中调用目标选择器。所以我查看了initWithNormalSprite方法,发现:
-(id) initWithNormalSprite:(CCNode<CCRGBAProtocol>*)normalSprite selectedSprite:(CCNode<CCRGBAProtocol>*)selectedSprite disabledSprite:(CCNode<CCRGBAProtocol>*)disabledSprite target:(id)target selector:(SEL)selector
{
// avoid retain cycle
__block id t = target;
return [self initWithNormalSprite:normalSprite selectedSprite:selectedSprite disabledSprite:disabledSprite block:^(id sender) {
[t performSelector:selector withObject:sender];
} ];
}
我想我必须以某种方式调用_块函数,但我没有看到一个很好的例子来理解如何。我也不太清楚 * _block* 是什么:(。
现在,我应该继承 CCMenuItemSprite 并更改此行为吗?如果是这样,我该如何调用目标选择器?
提前致谢 :)