我正在对CCSprite进行子类化,以便为精灵对象制作旋转手势。
为此,我需要使用CCTargetedTouchDelegate和CCStandardTouchDelegate 但即使在宣布这些代表的功能后,我也会出现歧义错误。
错误屏幕截图: -
代码。
namespace mygames
{
class DragSprite: public cocos2d::CCSprite, public cocos2d::CCTargetedTouchDelegate, public cocos2d::CCStandardTouchDelegate
{
public:
cocos2d::CCSize canvasSize;
bool init();
static DragSprite* createWithFile(const char *pszFileName);
bool isTouchingOnSprite(cocos2d::CCPoint touch);
virtual bool ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent);
virtual void ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent);
virtual void ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent);
virtual void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) ;
virtual void ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) ;
virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) ;
virtual void ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent) ;
float angleBetweenLineInDegrees(cocos2d::CCPoint startLineA,cocos2d::CCPoint endLineA,cocos2d::CCPoint startLineB,cocos2d::CCPoint endLineB);
~DragSprite();
CREATE_FUNC(DragSprite);
private :
bool isDrag;
bool isPinch;
bool canRotate;
cocos2d::CCPoint whereTouch;
cocos2d::CCPoint midPoint;
int touchNumber;
float lastDistance;
float distance;
float lastAngle;
float angle;
float cumulatedAngle;
float spriteAngle;
float innerRadious;
float outerRadious;
cocos2d::CCArray * touches;
cocos2d::CCTouch *firstTouch;
cocos2d::CCTouch *secondTouch;
float touchDistanceLast;
float touchDistanceNow;
};
}
我的.cpp文件中与错误相关的代码
DragSprite* DragSprite::createWithFile(const char *pszFileName)
{
DragSprite *pSprite = new DragSprite();
if (pSprite&&pSprite->initWithFile(pszFileName))
{
cocos2d::CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(pSprite, 0, true);
cocos2d::CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(pSprite, 0);
pSprite->setAnchorPoint(ccp(0.5, 0.5));
pSprite->autorelease();
return pSprite;
}
CC_SAFE_DELETE(pSprite);
return NULL;
}
bool DragSprite::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
//some code.....
return false/true;
}
void DragSprite::ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
//Some Code....
}
void DragSprite::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
//Some Code....
}
void DragSprite::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
CCLOG("TSB");
}
void DragSprite::ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
CCLOG("TSM");
}
void DragSprite::ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
CCLOG("TSE");
}
void DragSprite::ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
CCLOG("TSC");
}