下面我来介绍一下手势条纹的应用,水果忍者游戏是一个典型的应用例子。
//触摸注册事件
void HelloWorld:: registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
}
this->setTouchEnabled(true);
CCMotionStreak *motionStreak = CCMotionStreak::create(0.8f, 1, 10, ccORANGE, "Icon-Small.png"); //第一个参数是拖尾长度,第二个是每个多少像素点绘制一次,条纹粗细,颜色,图片 this->addChild(motionStreak,2,102);
//单点触摸 bool HelloWorld:: ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { return true; } //触摸移动 void HelloWorld:: ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) { //绘制手势条纹 CCMotionStreak *motionstreak = (CCMotionStreak *)this->getChildByTag(102); motionstreak->setPosition(pTouch->getLocation()); //玩家精灵随着鼠标拖动而动 player->setPosition(pTouch->getLocation()); }