这是我的问题我正在尝试为 iphone 的 cocos2d 中的动作序列创建一个回调函数,但我不断收到错误的访问错误。
在这里我创建了我的回调
id myCallFunc = [CCCallFuncND actionWithTarget:self.delegate selector:@selector(playerAttack:data:) data:(__bridge void *)([[PlayerAttackPacket alloc] initWithPlayer:@"" attackChoice: [NSNumber numberWithInt: item.tag]]) ]; // to call our method
这是被回调的函数,当转换数据时,编译器说访问不正确。
-(void) playerAttack:(id)sender data:(void *)data
{
PlayerAttackPacket* packet = (__bridge PlayerAttackPacket*)data;
BattleModel *model = [BattleModel sharedInstance];
int choice = packet.attackChoice.intValue;
NSString * players = packet.player;
}
播放器包:
@interface PlayerAttackPacket : NSObject {
NSString * player;
NSNumber * attackChoice;
}
@property (nonatomic, retain) NSString * player;
@property (nonatomic, retain) NSNumber * attackChoice;
-(id) initWithPlayer: (NSString*)_player attackChoice: (NSNumber*)choice;
@end
@implementation PlayerAttackPacket
@synthesize player,attackChoice;
-(id) initWithPlayer: (NSString*)_player attackChoice: (NSNumber*)choice
{
if((self=[super init]))
{
self.player = _player;
self.attackChoice = choice;
}
return self;
}
@end
谁能告诉我我做错了什么?=(。我的感觉是它与 ARC 有关,但我不确定。