Question

My code has two Bullet-related classes. Bullet and BulletCache. The BulletCache creates a certain number of

I have moved on to just creating a new bullet creating method meant to shoot off the bullets. I used the CCFuncN method but the game is currently throwing NSException errors:

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'

edit:

For further help and advice here is the shootBulletFrom method in the BulletCache.

This method is in the 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;
    }
}

I was also recommended to change the [CCCallFuncN] call at the bottom to:

[CCCallFuncN actionWithTarget:self selector:@selector(shootBulletFrom:shotPos velocity:velocity frameName:@"bullet1big.png" isPlayerBullet: YES)],

But then I got the compile Error: Expected ':' before Velocity

Was it helpful?

Solution

You have not mentioned the code for shootBulletFrom, and the error denoted that there is some mistake in the same. May be you have not declared the function in .h file or some other. So if possible mention so.

You can go through this and this links. They are having good examples for bullet firing apps. Hope that helps you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top