我是 Cocos2d 的新手,尝试从普通的 Cocoa Touch 移植到 Cocos2d 游戏。
我通过自定义方法创建了一些按钮:
+ (CCMenuItem *)createMenuItemImageWithNormalImage:(NSString *)normalImage selectedImage:(NSString *)selectedImage tag:(int)tag target:(id)target selector:(SEL)selector position:(CGPoint)position {
CCMenuItem *item = [CCMenuItemImage itemWithNormalImage:normalImage selectedImage:selectedImage];
item.tag = tag;
[item setTarget:target selector:selector];
item.position = [TSCCTransform transformPositionFromCocoaTouchToCocos2d:CGPointMake(position.x, position.y)];
return item;
}
按钮:
[self addChild:[TSCCLayer createMenuItemImageWithNormalImage:@"btn-mouse-dec.png" selectedImage:@"btn-mouse-dec.png" tag:0 target:self selector:@selector(changeNumberOfPlayers:) position:ccp([TSCCTransform winSizeWidth] - 140, 146)]];
但是当我点击它时什么也没发生。问题出在哪里?如何正确执行?