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

来源:未知 责任编辑:责任编辑 发表时间:2013-11-18 20:55 点击:
运行环境:vs2010 cocos2d-x2.2  p> 

p>

p> 

p>运行环境:vs2010 cocos2d-x2.2 

p>ActionManager看名字就知道是对整个Action的管理,我们可以通过单例的CCDirector来获得ActionManager,通过ActionManager我们可以控制某个精灵对象移动。

p>1.先设置一个精灵的移动:

p>                        CCAnimation* pSpriteAnimation = CCAnimation::create();

p>                        pSpriteAnimation->setLoops(-1);

p>                        pSpriteAnimation->setDelayPerUnit(0.1f);

p>                        pSpriteAnimation->addSpriteFrameWithFileName( "loading_02.png" );

p>                        pSpriteAnimation->addSpriteFrameWithFileName( "loading_03.png" );

p>                        pSpriteAnimation->addSpriteFrameWithFileName( "loading_04.png" );

p>                        CCAnimate* animate = CCAnimate::create(pSpriteAnimation);

p>                        pSprite->runAction(animate);

p>2.加入一个控件就是图片上显示的pause,这里点击一下就会调用3中所写的暂停。

p> 

p>                        CCControlButton* controlButton = CCControlButton::create("pause" , "Arial",52);

p>                        controlButton->setPosition(size.width - controlButton->getContentSize().width/2,size.height -

p>                                    controlButton->getContentSize().height/2);

p>                        controlButton->addTargetWithActionForControlEvents( this ,

p>                                    cccontrol_selector(HelloWorld::testPause),CCControlEventTouchDown);

p>3.ActionManager控制精灵的暂停与继续播放示例代码:

p>            CCDirector* director = CCDirector::sharedDirector();

p>            

p>             if (!isPause)

p>            {

p>                        director->getActionManager()->pauseTarget( this ->getChildByTag(1));

p>                        isPause=!isPause;
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • cocos2d-x学习笔记(19)--label 、label atlas
  • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
  • Cocos2d-x学习(一):HelloWorld
  • cocos2dx在xcode下开发,编译到android上(2)
  • cocos2d 设置屏幕默认方向
  • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
  • Cocos2d-x 2.0 之 Actions “三板斧” 之一
  • cocos2d-x学习笔记(18)--游戏打包(windows平台)
  • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1