制作子弹Fire -Cocos2d

时间:2012-01-02 22:59:13

标签: objective-c cocos2d-iphone projectile

我的代码有两个与Bullet相关的类。 Bullet和BulletCache。 BulletCache创建了一定数量的

我已经开始创建一个新的子弹创建方法,用于射击子弹。我使用了CCFuncN方法,但游戏当前正在抛出NSException错误:

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之前预期':'

1 个答案:

答案 0 :(得分:1)

你还没有提到shootBulletFrom的代码,错误表示同样存在一些错误。可能是你没有在.h文件或其他文件中声明该函数。所以,如果可能的话,请提及。

您可以浏览thisthis个链接。他们有很好的子弹射击应用程序示例。希望对你有帮助。