摘要:关于scheduleUpdate看这篇即可http://www.benmutou.com/blog/archives/56接下来是示例代码: CCSize size = CCDirector::sharedDirector()->getWinSize(); //创建二个精灵,一绿一红 CCSprite *psSprite1 = CCSprite::create("green.png"); CCSprite *psSprite2 = CCSprite::create("red.png"); //利用精灵创建进度条,并设置一些属...
阅读全文
随笔分类 - cocos2d-x
摘要:pSprite->setAnchorPoint(CCPoint(0,0)); pSprite->setPosition(CCPoint(300,700)); CCFiniteTimeAction* pAcion = CCEaseElasticOut::actionWithAction( CCMoveTo::create(1.0f,CCPoint(300,300)),0.6f);//通过第二个参数来调整振幅,或者速度,值越大越慢振幅越小 pSprite->runAction( CCRepeatForever::create( ...
阅读全文
摘要:关于ccTouchesEnded看这个博客即可http://blog.linguofeng.com/archive/2012/09/12/cocos2d-x-touch.htmlclass ClickAndMoveTestScene : public TestScene{public: virtual void runThisTest();};class MainLayer : public CCLayer{public: MainLayer(); virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);};...
阅读全文
摘要:CCLayer中的setTouchEnabled(true)会开启多点触摸。 如果使用CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,true); 只会开启一个点的触摸。 当HelloWorld::ccTouchBegan返回为false的时候,TouchDispatcher将会相应下一个优先级的触摸代理。 bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { return false; } ,如
阅读全文
摘要:CCActionInterval* createEffect(int nIndex, float t){ CCDirector::sharedDirector()->setDepthTest(false); switch(nIndex) { case 0: return Shaky3DDemo::create(t); case 1: return Waves3DDemo::create(t); case 2: return FlipX3DDemo::create(t); case 3: return FlipY3DDem...
阅读全文
摘要:Test中使用的特效如下首先,使用ccg(x,y)建grid,一个Grid属性就好像一个矩阵,是一个网络的线,组成一系列的方块和矩阵。一个(16,12)大小的grid将会运行的非常快,但是并不会看起来非常的好。(32,24)的将会看起来非常棒,但是在iphone1代中,运行起来不会太快。任何一个屏幕的Frame都会改称成一个Texture(FBO),这个纹理会转换城一个顶点array,这个顶点坐标array是通过grid的效果转换来的。最后,这个顶点数组被显示到屏幕上。CCShaky3D::actionWithRange(5,true,ccg(15,10),t);//第一个参数是扭曲范围,第二
阅读全文
摘要:在cocos2d中同样提供了很多表现图片和精灵的方式,上一篇当中提到的切换场景的方式之一是顺或逆时针切入的方法,在图片上也可以使用,test里有一个例子介绍CCProgressTimer可以实现一些图片的特效效果,这样的效果可以在载入的时候作为载入动画步骤1.定义CCProgressTo,通过actionWithDuration函数,第一个参数是时间是一个CCTime对象,第二个参数是结果显示图片的百分比,如例子中一个100%,一个50%步骤2 定义CCProgressTimer,通过progressWithFile,参数是图片路径步骤3 调用setType设置类型,kCCProgressTi
阅读全文
摘要:CCTransitionScene* createTransition(int nIndex, float t, CCScene* s){ // fix bug #486, without setDepthTest(false), FlipX,Y will flickers CCDirector::sharedDirector()->setDepthTest(false); switch(nIndex) { case 0: return CCTransitionJumpZoom::create(t, s); case 1: return CCTransiti...
阅读全文
摘要://程序开始后延时2秒才开始addSprite函数scheduleOnce(schedule_selector(Issue1305::addSprite), 2);转到定义:void CCNode::scheduleOnce(SEL_SCHEDULE selector, float delay){ this->schedule(selector, 0.0f, 0, delay);}void Issue1305::addSprite(float dt){ m_pSpriteTmp->setPosition(ccp(250,250)); addChild(m_pSpriteTmp...
阅读全文
摘要:CCSet *m_pPausedTargets;类的成员变量void CCNode::schedule(SEL_SCHEDULE selector, float interval, unsigned int repeat, float delay)void PauseResumeActions::onEnter(){ ActionsDemo::onEnter(); this->centerSprites(2); m_tamara->runAction(CCRepeatForever::create(CCRotateBy::create(3, 360))); ...
阅读全文
摘要:在class HelloWorld : public cocos2d::CCLayer中添加void draw();实现:void HelloWorld::draw(){ CCSize s = CCDirector::sharedDirector()->getWinSize(); CCPointArray *array = CCPointArray::create(20); array->addControlPoint(ccp(0, 0)); array->addControlPoint(ccp(80, 80)); array->addControlPoint(c...
阅读全文
摘要:CCCatmullRomBy:把某一对象以Catmull-Rom curve曲线移动一段距离 CCPointArray *array = CCPointArray::create(20); array->addControlPoint(ccp(0, 0)); array->addControlPoint(ccp(80, 80)); array->addControlPoint(ccp(s.width - 80, 80)); array->addControlPoint(ccp(s.width - 80, s.height - 80)); array-...
阅读全文
摘要:class CC_DLL CCCallFunc : public CCActionInstant //void Issue1305_2::onEnter(){ ActionsDemo::onEnter(); centerSprites(0); CCSprite *spr = CCSprite::create("Images/grossini.png"); spr->setPosition(ccp(200,200)); addChild(spr); CCMoveBy* act1 = CCMoveBy::create(2 ,ccp(0, 100)); //...
阅读全文
摘要:改变动作执行对象CCTargetedAction通常默认的动作执行对象是调用runAction的对象,而CCTargetedAction可以改变动作执行对象。CCTargetedAction* t = CCTargetedAction::create(sprite2, moveto);sprite->runAction(CCSequence::create(moveto, t, moveto, NULL));sprite先moveto,然后sprite2执行moveto,最后sprite执行moveto。void ActionTargeted::onEnter(){ ActionsDem
阅读全文
摘要:CCActionInterval* move1 = CCMoveBy::create(1, ccp(250,0)); CCActionInterval* move2 = CCMoveBy::create(1, ccp(0,50)); CCToggleVisibility* tog1 = new CCToggleVisibility(); CCToggleVisibility* tog2 = new CCToggleVisibility(); tog1->autorelease(); tog2->autorelease(); //目前的理解是夹...
阅读全文
摘要:有限次执行一组动作和无限次执行一组动作void ActionRotateJerk::onEnter(){ ActionsDemo::onEnter(); centerSprites(2); CCFiniteTimeAction* seq = CCSequence::create( CCRotateTo::create(0.5f, -20), CCRotateTo::create(0.5f, 20), NULL); CCActionInterval* rep1 = CCRepeat::create(seq, 10); C...
阅读全文
摘要:voidremoveFromParentAndCleanup(bool cleanup)//删除父节点中的当前节点并清除动作及回调函数void ActionCallFuncND::onEnter(){ ActionsDemo::onEnter(); centerSprites(1); CCFiniteTimeAction* action = CCSequence::create(CCMoveBy::create(2.0f, ccp(200,0)), CCCallFuncND::create(this, callfuncND_selector(ActionCall...
阅读全文
摘要:CCFollow动作,可以让一个节点跟随另一个节点做位移。CCFollow经常用来设置layer跟随sprite,可以实现类似摄像机跟拍的效果效果是精灵在地图上移动,地图也会跟着移动,但是精灵仍然是在整个界面的中心位置CCSize s = CCDirector::sharedDirector()->getWinSize(); pSprite->setPosition(ccp(-200, s.height / 2)); CCActionInterval* move = CCMoveBy::create(2, ccp(s.width * 3, 0)); ...
阅读全文
摘要:Cocos2d-x提供了一中根据球面坐标轨迹旋转的方式CCOrbitCameraCC_DEPRECATED_ATTRIBUTE static CCOrbitCamera* actionWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);参数分别为旋转的时间,起始半径,半径差,起始z角,旋转z角差,起始x角,旋转x角差CCActionInterval* orbit1 = CCOrbitCamera::cre.
阅读全文
摘要:void ActionDelayTime::onEnter(){ ActionsDemo::onEnter(); alignSpritesLeft(1); CCActionInterval* move = CCMoveBy::create(1, ccp(150,0)); CCFiniteTimeAction* action = CCSequence::create( move, CCDelayTime::create(2), move, NULL); m_grossini->runAction(action);}连续动作的反向动作void ActionReve...
阅读全文