当前位置:编程学习 > wap >>

cocos2d-x ActionManager控制精灵的暂停运动

运行环境:vs2010 cocos2d-x2.2 
 
 
运行环境:vs2010 cocos2d-x2.2 
ActionManager看名字就知道是对整个Action的管理,我们可以通过单例的CCDirector来获得ActionManager,通过ActionManager我们可以控制某个精灵对象移动。
1.先设置一个精灵的移动:
                        CCAnimation* pSpriteAnimation = CCAnimation::create();
                        pSpriteAnimation->setLoops(-1);
                        pSpriteAnimation->setDelayPerUnit(0.1f);
                        pSpriteAnimation->addSpriteFrameWithFileName( "loading_02.png" );
                        pSpriteAnimation->addSpriteFrameWithFileName( "loading_03.png" );
                        pSpriteAnimation->addSpriteFrameWithFileName( "loading_04.png" );
                        CCAnimate* animate = CCAnimate::create(pSpriteAnimation);
                        pSprite->runAction(animate);
2.加入一个控件就是图片上显示的pause,这里点击一下就会调用3中所写的暂停。
 
                        CCControlButton* controlButton = CCControlButton::create("pause" , "Arial",52);
                        controlButton->setPosition(size.width - controlButton->getContentSize().width/2,size.height -
                                    controlButton->getContentSize().height/2);
                        controlButton->addTargetWithActionForControlEvents( this ,
                                    cccontrol_selector(HelloWorld::testPause),CCControlEventTouchDown);
3.ActionManager控制精灵的暂停与继续播放示例代码:
            CCDirector* director = CCDirector::sharedDirector();
            
             if (!isPause)
            {
                        director->getActionManager()->pauseTarget( this ->getChildByTag(1));
                        isPause=!isPause;
            } else if (isPause)
            {
                        director->getActionManager()->resumeTarget( this ->getChildByTag(1));
                        isPause=!isPause;
            }
我们看pauseTarget的声名为:
     /** Pauses the target: all running actions and newly added actions will be paused.
    */
    void pauseTarget(CCObject *pTarget); 
对传入的对象进行暂停。
补充:移动开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,