一、拖动渐隐效果类 CCMotionStreak
定义CCMotionStreak对象
void MotionStreakTest2::onEnter(){
MotionStreakTest::onEnter();
setTouchEnabled(true);
CCSize s = CCDirector::sharedDirector()->getWinSize();
streak = CCMotionStreak::creat(3,3,64,ccWHITE,s_streak); /* 第一个参数是渐隐的时间,第二个参数是间隐片断的大小,第三 个参数是贴图的宽高,第四个参数是颜色,最后一个参数是贴图的路 */
addChild(streak);
streak->setPosition(CCPointMake(s.width/2,s.height/2));
}
void MotionStreakTest2::ccTouchesMoved(CCSet* touches,CCEvent* event){
CCSetIterator it = touches->begin();
CCTouch* touch = (CCTouch*)(*it);
CCPoint touchLocation = touch->locationInView();
touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);
streak->setPosition(touchLocation);
}
二、绘制图形
1、绘制直线:
ccDrawLine(ccp(0,0),ccp(s.width,s.height)); // 默认白色、不透明、线宽为1、抗锯齿
设置参数后绘制直线:
glLineWidth(5.0f);
ccDrawColor4B(255,0,0,255);
CCDrawLine(ccp(0,s.height),ccp(s.width,0));
// OpenGL是状态机,除非重新设置,否则参数会保持到下一个状态
2、绘制点:
// OpenGL中点是方形的
CCPoint points[] = {ccp(60,60),ccp(70,70),ccp(60,70),ccp(70,60)};
ccPointSize(4);
ccDrawColor4B(0,255,255,255);
ccDrawPoints(points,4);
3、画圆:
glLineWidth(2);
ccDrawColor4B(0,255,255,255);
ccDrawCircle(ccp(s.width/2,s.heigth/2),50,CC_DEGREES_TO_RADIANS(90),50,true);
// 参数:圆心,半径,角度,分段数,是否与圆心相连
4、画多边形:
ccDrawColor4B(255,0,255,255);
glLineWidth(2);
CCPoint vertices2[] = {ccp(30,130),ccp(30,230),ccp(50,200)};
ccDrawPoly(vertices2,3,true);
// 参数:点数组,点个数,图形是否关闭
5、画贝塞尔曲线:
CHECK_GL_ERROR_DEBUG();
// draw quad bezier path
ccDr awQuadBezier(ccp(0,s.height), ccp(s.width/2,s.height/2), ccp(s.width,s.height), 50);
CHECK_GL_ERROR_DEBUG();
// draw cubic bezier path
ccDrawCubicBezier(ccp(s.width/2, s.height/2), ccp(s.width/2+30,s.height/2+50),
ccp(s.width/2+60,s.height/2-50),ccp(s.width, s.height/2),100);
三、时间调度
所有的CCNode类的子类都有这样滴函数
schedule(schedule_selector(SchedulerAutoremove::autoremove),0.5f);
//按时调用一个函数autoremove,参数2是时间间隔
UnSchedule(schedule_selector(SelectorAutoremove::autoremove));
//结束时间调度
m_pPauseTargets = pDirector->getScheduler()->pauseAllTargets();
CC_SAFE_RETAIN(m_pPausedTargets);
//暂停schedule
pDirector->getScheduler()->resumeTargets(m_pPausedTargets);
CC_SAFE_RELEASE_NULL(m_pausedTargets);
//继续schedule
CCDirector::sharedDirector()->getScheduler()->unscheduleAllSelectors();
//使所有schedule停止
// 有一种固定的调用方式:使用scheduleUpdate会在0.01s调用一次update,只需重载update