I’m using HelloWorld sample project to learn and I can’t get ccTouchBegan to work.
`void HelloWorld::onEnter()
{
CCDirector* pDirector = CCDirector::sharedDirector();
- pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false);*
CCNode::onEnter();
}
void HelloWorld::onExit()
{
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->removeDelegate(this);
CCNode::onExit();
}
`
o@n bold part I get this error:
Ambiguous conversion from derived class ‘HelloWorld’to base class ’cocos2d::CCTouchDelegate’:
Here is my .h
#ifndef HELLOWORLD_SCENE_H
#define HELLOWORLD_SCENE_H
#include “cocos2d.h”
//using namespace cocos2d;
class HelloWorld : public cocos2d::CCLayer, public cocos2d::CCTargetedTouchDelegate
{
public:
// Here’s a difference. Method ‘init’ in cocos2d-x returns bool, instead of returning ‘id’ in cocos2d-iphone
virtual bool init();
// there’s no ‘id’ in cpp, so we recommend returning the class instance pointer
static cocos2d::CCScene* scene();
//a selector for category selected
void buttonPress(cocos2d::CCMenuItemImage *sender);
//a selector for item selected
void itemSelected(cocos2d:: CCMenuItemImage *sender);
/// Returns true if the touch is within the boundary of our sprite
bool isTouchingSprite(cocos2d::CCTouch* touch);
//Users/Developer/Downloads/cocos2d-x-2.2.1/projects/testProject/Classes/HelloWorldScene.cpp
virtual void onEnter();
virtual void onExit();
virtual bool ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event);
virtual void ccTouchMoved(cocos2d::CCTouch* touch, cocos2d::CCEvent* event);
virtual void ccTouchEnded(cocos2d::CCTouch* touch, cocos2d::CCEvent* event);
// implement the “static node()” method manually
CREATE_FUNC(HelloWorld);
};
#endif // HELLOWORLD_SCENE_H@