Cocos2d入门 <三>如何移动精灵角色
来源:互联网 发布:w10无法安装软件 编辑:程序博客网 时间:2024/05/01 22:49
void HelloWorld::addTarget(){CCSprite *target = CCSprite::create("Target.png",CCRectMake(0,0,27,40));// Determine where to spawn the target along the Y axisCCSize winSize = CCDirector::sharedDirector()->getWinSize();int minY = target->getContentSize().height/2;int maxY = winSize.height - target->getContentSize().height/2;int rangeY = maxY - minY;// srand( TimGetTicks() );int actualY = ( rand() % rangeY ) + minY;// Create the target slightly off-screen along the right edge,// and along a random position along the Y axis as calculatedtarget->setPosition(ccp(winSize.width + (target->getContentSize().width/2),actualY) );this->addChild(target);// Determine speed of the target int minDuration = (int)2.0;int maxDuration = (int)4.0;int rangeDuration = maxDuration - minDuration;// srand( TimGetTicks() );int actualDuration = ( rand() % rangeDuration )+ minDuration;// Create the actionsCCFiniteTimeAction* actionMove =CCMoveTo::create( (float)actualDuration,ccp(0 - target->getContentSize().width/2, actualY) );CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create( this, callfuncN_selector(HelloWorld::spriteMoveFinished)); target->runAction( CCSequence::create(actionMove, actionMoveDone, NULL) );}// cpp with cocos2d-xvoid HelloWorld::spriteMoveFinished(CCNode* sender){ CCSprite *sprite = (CCSprite *)sender; this->removeChild(sprite, true);}// cpp with cocos2d-xvoid HelloWorld::gameLogic(float dt){ this->addTarget();}// on "init" you need to initialize your instancebool HelloWorld::init(){ ...... // Call game logic about every secondthis->schedule( schedule_selector(HelloWorld::gameLogic), 1.0 ); return true;}
- Cocos2d入门 <三>如何移动精灵角色
- 如何移动一个cocos2d-x精灵 之三
- 【cocos2d-x 初级教程之三 2.x版本】如何移动一个cocos2d-x精灵
- 如何移动一个cocos2d-x精灵
- 如何移动一个cocos2d-x精灵
- Cocos2d-x 精灵移动
- cocos2d-x SimpleGame(2)如何移动一个精灵
- Cocos2d-x中,如何通过触摸来移动一个精灵
- Cocos2D-X SimpleGame 如何移动一个cocos2d-x精灵 (2) ----版本cocos2d-2.0-x-2.0.3 .
- cocos2d-x Touch 移动精灵
- cocos2d-x中精灵移动
- 如何在Cocos2D 1.0 中掩饰一个精灵(三)
- cocos2d-X之精灵角色(CCSprite)
- 精灵三秒消失 cocos2d
- 【Cocos2d-x】新手自学(三)虚拟屏幕摇杆,控制精灵移动
- Cocos2d-x 2.0 百例精讲:如何让一个精灵跟随触点移动
- Cocos2d-x基础示例-精灵移动1
- Cocos2d-x 基础示例-精灵移动2
- jq 幻灯片
- Cocos2d入门 <二> 添加一个精灵
- 看IT人才最容易犯的17个错误
- 宝贝与iPad-新生代的玩具
- php验证码
- Cocos2d入门 <三>如何移动精灵角色
- ASH
- 面向对象的程序设计-学习笔记-25-运用实例
- Cocos2d入门 <四> fire bullet
- 玩转vim之查看编译出错信息
- Mysql union order by 总结一下
- jdk环境变量配置
- STATSPACK
- settings PreferenceActivity网博收录