简体   繁体   中英

'Receiver type “CCParticleBatchNode” for class message is a forward declaration'

The title speaks for itself. I installed cocos2d 1.1 by downloading the files from github, removing the cocos2d project inside my project and re-adding it.

I have a '@class CCParticleBatchNode' in my header file and #import "cocos2d.h" both in my prefix and in the relevant implementation file. When i browse to the location CCParticleBatchNode should be, it is there.

So, does someone know what the problem might be? :)

Edit: Here's some code.

#import "PrecipicationLayer.h"
#import "cocos2d.h"

@implementation PrecipicationLayer
@synthesize cloudLayer;
- (id)init
{
    self = [super init];
    if (self)
    {
        rain = [CCParticleRain node];
        rainBatch = [CCParticleBatchNode particleBatchNodeWithFile:@"Raindrop48px.png" capacity:400 useQuad:YES additiveBlending:NO];
        [self addChild:rainBatch];

        [self schedule:@selector(tick:)];
    }
return self;
}

and the header file:

#import <Foundation/Foundation.h>
#import "cocos2d.h"
@class CCParticleBatchNode;

@interface PrecipicationLayer : CCLayer {
    CCParticleBatchNode *rainBatch;
}

@end

All irrelevant parts have been removed.

There is no need to import cocos2d.h in your .m file if you have imported it in your .h file. I don't think that's the problem, though.

There are two possibilities:

  • CCParticleBatchNode is defined in cocos2d.h, in which case you don't need a forward declaration and this may be confusing the compiler.
  • CCParticleBatchNode is not defined in cocos2d.h, in which case you need to import CCParticleBatchNode.h in your implementation file as all you have is the forward declaration.

"removing the cocos2d project inside my project and re-adding it."

Check that the files are part of the build process. In XCode 4, click the project name in the top of the Project Navigator, select "Build Phases," make sure "cocos2d libraries" is shown under the target name. If it is, then expand "Target Dependencies," and make sure it's also listed there. Then expand "Link binary with Libraries" and make sure it's also added there.

Oh well … the usual cocos2d upgrade troubles.

Personally I would simply install the cocos2d 1.1 templates (assuming they're up to date) and create a project based on one of the cocos2d templates. Then add your source code and resources to this newly created project. This usually works a lot better than trying to replace and update the cocos2d code in an existing project.

I guess that your problem may be coming from removing the cocos2d project but not the files from your hard drive. That means there can still be some left-over files from the old version that are still included in the project and built. You definitely want to delete all existing cocos2d files before moving the new cocos2d files in place.

Finally, don't rule out the possibility that the version you downloaded from github is broken. It wouldn't be the first time. Try using the downloadable version from the website instead, and keep in mind that 1.1 is just a beta at this point in time.

Tip: in future you may want to create cocos2d projects with Kobold2D , it has an upgrade tool that does away with all those troubles.

I had the same problem when downloading the newest templates. The problem was that even though the files CCParticleBatchNode.h and CCParticleBatchNode.m were present physically, they had not been added to the Xcode project template. I just had to add them to the project and then it compiled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM