刚入门cocos2dx,最近遇到一个问题,就是声明总是显示语法错误,实在弄不懂,求大神指点一下。
函数声明:
bool onTouchesBegan(const std::vector<Touch*>& touches, Event * event);
void onTouchesEnded(const std::vector<Touch*>& touches, Event * event);
//触摸打开
this->setTouchEnabled(true);
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto listener1 = EventListenerTouchAllAtOnce::create();
listener1->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this);
listener1->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this);
dispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
//触摸效果函数
bool HelloWorld::onTouchesBegan(const std::vector& touches, Event *event)
{
return true;
}
void HelloWorld::onTouchesEnded(const std::vector& touches, Event *event)
{
CCTouch* touch = (CCTouch*)touches->anyObject();
CCPoint locInView = touch -> getLocationInView();
CCPoint loc = Director::getInstance()->convertToUI(locInView);
//子弹距离和速度计算公式
if (loc.x <= 20)
{
return;
}
CCSize screenSize = CCDirector::sharedDirector()->getVisibleSize();
CCSprite* proj = CCSprite::create("projectile.png");
proj->setPosition(20, screenSize.height / 2.0);
this->addChild(proj);
double dx = loc.x - 20;
double dy = loc.y - screenSize.height / 2.0;
double d = sqrt(dx * dx + dy * dy);
double D = sqrt(screenSize.width * screenSize.width + screenSize.height * screenSize.height);
double ratio = D / d;
double endx = ratio * dx + 20;
double endy = ratio * dy + screenSize.height / 2.0;
CCMoveTo* move = CCMoveTo::create(D / 320, ccp(endx, endy));
CCCallFuncN* moveFinish = CCCallFuncN::create(this, callfuncN_selector(HelloWorld::myDefine));
CCSequence* actions = CCSequence::create(move,moveFinish,NULL);
proj->runAction(actions);
}
```
恳求大神过目和解答,谢谢