Can't create the child class of CCSprite


#1

I want to create a new class which is a child class of CCSprite. But it doesn’t work.

It got the error CCBullet does not name a type

Please take a look and tell me some your ideas to solve my problems. Thanks.

CCBullet.h

#ifndef __GameplayScene_H__
#define __GameplayScene_H__

#include "cocos2d.h"
#include "common/Define.h"

#if ENABLE_PHYSICS_BOX2D_DETECT
#include "../../Box2DTestBed/GLES-Render.h"
#include "Box2D/Box2D.h"
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
#include "chipmunk.h"
#endif

USING_NS_CC;

class CCBullet : public cocos2d::CCSprite
{
public:
    static CCBullet* create(int bulletID, const char *filePath);
    int mBulletID; 
    float mSpeed;
    float mStrength; 
    float mPushBack; 
    float mCritical; 
    float mFanShoot; 
    float mSpread;
    float mAngle;
};

#endif

CCBullet.cpp

#include "common/Define.h"
USING_NS_CC;
using namespace cocos2d;
using namespace cocos2d::extension;

CCBullet* CCBullet::create(int bulletID, const char *filePath){
    CCBullet *pobSprite = new CCSprite();
    if (pobSprite && pobSprite->initWithFile(filePath))
    {       
        pobSprite->mBulletID = bulletID;    
        pobSprite->mAngle = 0;
        pobSprite->mSpeed = 0;
        pobSprite->mStrength = 0;
        pobSprite->mPushBack = 0;
        pobSprite->mCritical = 0;
        pobSprite->mFanShoot = 0;
        pobSprite->mSpread = 0;
        pobSprite->autorelease();
        return pobSprite;
    }
    CC_SAFE_DELETE(pobSprite);
    return NULL;
}

#2

change “CCBullet *pobSprite = new CCSprite();” to “CCBullet *pobSprite = new CCBullet();”


#3

@wpstu Thank for your quick reply. I’ll try. One more question. How can I get properties of CCBullet object like speed, angle (I updated my questions)?


#4

@lolyoshi i think this is not a problem of cocos2d-x but a problem of c++,you can get help through google/baidu.


#5

@wpstu I tried but it still causes the error :frowning: