Objective c 让子弹开火-Cocos2d
我的代码有两个与Bullet相关的类。子弹和子弹缓存。BulletCache创建一定数量的 我已经开始创建一种新的子弹创建方法,用于发射子弹。我使用了CCFuncN方法,但游戏当前抛出了NSException错误:Objective c 让子弹开火-Cocos2d,objective-c,cocos2d-iphone,projectile,Objective C,Cocos2d Iphone,Projectile,我的代码有两个与Bullet相关的类。子弹和子弹缓存。BulletCache创建一定数量的 我已经开始创建一种新的子弹创建方法,用于发射子弹。我使用了CCFuncN方法,但游戏当前抛出了NSException错误: CCAction* action = [CCSequence actions: [CCAnimate actionWithAnimation:[profile getAnimation:@"attack" index:currentDir]],
CCAction* action = [CCSequence actions:
[CCAnimate actionWithAnimation:[profile getAnimation:@"attack" index:currentDir]],
[CCCallFuncN actionWithTarget:self selector:@selector(shootBulletFrom:)],
nil];
NSInvalidArgumentException', reason: '-[Player shootBulletFrom:]: unrecognized selector sent to instance 0x703ec70'
编辑:
有关进一步的帮助和建议,请参阅BulletCache中的shootBulletFrom方法
此方法位于BulletCache中
-(void) shootBulletFrom:(CGPoint)startPosition velocity:(CGPoint)velocity frameName:(NSString*)frameName
isPlayerBullet:(bool)isPlayerBullet
{
CCArray* bullets = [batch children];
CCNode* node = [bullets objectAtIndex:nextInactiveBullet];
NSAssert([node isKindOfClass:[Bullet class]], @"not a Bullet!");
Bullet* bullet = (Bullet*)node;
[bullet shootBulletAt:startPosition velocity:velocity frameName:frameName
isPlayerBullet:isPlayerBullet];
nextInactiveBullet++;
if (nextInactiveBullet >= [bullets count])
{
nextInactiveBullet = 0;
}
}
还建议我将底部的[CCCallFuncN]调用更改为:
[CCCallFuncN actionWithTarget:self selector:@selector(shootBulletFrom:shotPos velocity:velocity frameName:@"bullet1big.png" isPlayerBullet: YES)],
但是我得到了编译错误:在Velocity之前,您没有提到shootBulletFrom的代码,这个错误表示在相同的代码中有一些错误。可能您没有在.h文件或其他文件中声明函数。因此,如果可能的话,请提及
你可以浏览和链接。他们有子弹射击应用的好例子。希望这能对您有所帮助。看起来这两个代码都使用了单例模式,虽然这是我获取项目符号代码的来源,但这正是我试图改变的。我将bullet代码移植到的项目不使用单例模式,声音引擎除外。