【发布时间】:2014-03-12 18:30:26
【问题描述】:
下面是我的HelloWorld.h类:
class HelloWorld : public cocos2d::CCLayer
{
public:
HelloWorld();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
b2World* world;
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::CCScene* scene();
// a selector callback
void menuCloseCallback(CCObject* pSender);
// implement the "static node()" method manually
CREATE_FUNC(HelloWorld);
virtual void draw();
virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
virtual void ccTouchesMoved(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
virtual void ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
void update(float dt);
};
在我的HelloWorld.cpp 类中,我已经初始化了我的init 方法
bool HelloWorld::init(){
setTouchEnabled( true );
setAccelerometerEnabled( true );
scheduleUpdate();
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
return true;
}
这段代码现在对我有用! :)
【问题讨论】:
-
嗯只是猜测,尝试从 ccTouches* 方法声明中删除“virtual”关键字。
-
不。没用。 :(
-
cocos2d::CCLayer已经派生自cocos2d::CCTargetedTouchDelegate,请尝试将其从类定义中删除
标签: c++ sprite cocos2d-x ccsprite touchesbegan