我想創建一個新類,該子類是CCSprite
的子類。但它不起作用。無法在Cocos2d-x中創建CCSprite的子類。
它得到了錯誤CCBullet沒有指定類型
請看看,並告訴我一些你的想法來解決我的問題。謝謝。
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);
};
#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;
}
你說的 「它不工作」 是什麼意思?我想你必須實例化一個CCBullet而不是CCSprite。請將'new CCSprite()'換成'new CCBullet()'。 –
@LaurentZubiaur:它得到了錯誤CCBullet沒有命名我的問題中更新的類型。你對這個錯誤有什麼想法嗎? – lolyoshi
請仔細檢查CCBullet.cpp是否包含CCBullet.h。 –