在购买空地时,我们增加动画效果:
该动画包含2部分,第一部分是让脚印由小变大,再由大变小,第二部分是脚印变小后,播放一个粒子效果。
首先下载粒子编辑工具:Cocos2d-x-ParticleEditor这是一个开源免费的工具,下载地址为:
https://github.com/chaseli/Cocos2d-x-ParticleEditor-for-Windows
打开bin目录下的ParticleEditor.exe 开启工具,里面包含了粒子实例,我们可以从中选取部分粒子效果为我所用,也可以自己编辑效果,总之采用这个工具编辑粒子非常方便。大家可以边修改右边的数据边浏览效果。
我们开始修改一下我们的代码,把动作和粒子效果添加进来
1、 首先修改一下RicherGameController部分代码
<span >voID RicherGameController::endGo(){ GameBaseScene::pathMarkVector.at(stepHasGone)->setVisible(false); stepHasGone++; if(stepHasGone >= stepsCount) { //当角色走完之后,都调用handlePropEvent方法,处理道具相关事项 handlePropEvent(); return; } currentRow = nextRow; currentCol = nextCol; moveOnestep(_richerPlayer); log("go end"); }</span>
<span >voID RicherGameController::handlePropEvent(){…………………………… for (int i = 0; i < 4; i++) { Point ptMap = Util::GL2map(Vec2(positionAroundEnd[i][0],positionAroundEnd[i][1]),GameBaseScene::_map); int TitleID = GameBaseScene::landLayer->getTileGIDAt(ptMap); if(TitleID == GameBaseScene::blank_land_tiledID) {…………………………//在这里把角色的tag 从消息中发送出去 String * str = String::createWithFormat("%d-%f-%f-%d",MSG_BUY_BLANK_TAG,x,y,_richerPlayer->getTag()); NotificationCenter::getInstance()->postNotification(MSG_BUY,str); break; } }}</span>
2、修改GameBaseScene.cpp文件
<span >这个方法主要是把动作相关的脚印精灵加载进来,便于后期使用voID GameBaseScene::doSomeForParticle(){ scaleby1ForBuyLand = ScaleBy::create(0.1,1.5); scaleby2ForBuyLand = ScaleBy::create(0.5,0.7); scaleby1ForBuyLand->retain(); scaleby2ForBuyLand->retain(); foot1Sprite = Sprite::create(PLAYER1_1_PARTICLE_PNG); addChild(foot1Sprite); foot1Sprite->setAnchorPoint(ccp(0,0)); foot2Sprite = Sprite::create(PLAYER2_1_PARTICLE_PNG); addChild(foot2Sprite); foot2Sprite->setAnchorPoint(ccp(0,0));}</span>
<span >GameBaseScene.cpp中的receivednotificationOMsg方法根据消息分别处理voID GameBaseScene::receivednotificationOMsg(Object* data){………………………… case MSG_BUY_BLANK_TAG: { buy_land_x = messageVector.at(1)->floatValue(); buy_land_y = messageVector.at(2)->floatValue(); int playerTag = messageVector.at(3)->intValue(); //当接收到前面RicherGameController 发送来的购买空地块的消息后,根据角色分别处理 switch(playerTag) { case PLAYER_1_TAG: //当是主角时 ,调用showBuyLandDialog方法,d出对话框 交由人工处理 { showBuyLandDialog(MSG_BUY_BLANK_TAG); break; } case PLAYER_2_TAG://当是第二个角色时,不会d出对话框,直接买地,运行动画,播放粒子效果 { Point pointOfGL = Util::map2GL(ccp(buy_land_x,buy_land_y),GameBaseScene::_map); foot2Sprite->setVisible(true); foot2Sprite->setposition(pointOfGL); Point pointOfMap = ccp(buy_land_x,buy_land_y); foot2Sprite->runAction(Sequence::create(scaleby1ForBuyLand,scaleby2ForBuyLand,</span>
<span ><span > </span>CallFunc::create([this,pointOfMap,pointOfGL]() { playParticle(pointOfGL,PLAYER2_1_PARTICLE_PList); foot2Sprite->setVisible(false); landLayer->setTileGID(player2_building_1_tiledID,ccp(buy_land_x,buy_land_y)); NotificationCenter::getInstance()->postNotification(MSG_PICKONE_TOGO,String:<span > </span>:createWithFormat("%d",MSG_PICKONE_TOGO_TAG)); } ),NulL)); break; } } break; }…………………………………..}}</span>
3、
接着看主角(人工)点击对话框中的确认按钮后,动作的执行情况
<span >voID GameBaseScene::buyLandCallback(Node *pNode){ if(pNode->getTag() == Btn_OK_TAG) { switch(popDialog->getDataTag()) { case MSG_BUY_BLANK_TAG: { //当点击空白地块购买的确认按钮后,首先把land层地块的坐标转换成GL坐标 Point pointOfGL = Util::map2GL(ccp(buy_land_x,GameBaseScene::_map); foot1Sprite->setVisible(true); foot1Sprite->setposition(pointOfGL); Point pointOfMap = ccp(buy_land_x,buy_land_y); //让foot 图片顺序执行放大缩小的动画,然后调用playParticle方法,播放粒子效果 foot1Sprite->runAction(Sequence::create(scaleby1ForBuyLand,</span>
<span ><span > </span>CallFunc::create([this,pointOfGL](){ playParticle(pointOfGL,PLAYER1_1_PARTICLE_PList); //让foot图片隐藏,并设置land的Title的gID,更换成foot图块 foot1Sprite->setVisible(false); landLayer->setTileGID(player1_building_1_tiledID,pointOfMap); } ),NulL)); log( "need 00 "); break; } case MSG_BUY_LAND_1_TAG: …………………….. } popDialog->setVisible(false); //1秒后,发送消息,让其他角色行走 this->scheduleOnce(schedule_selector( GameBaseScene::sendMSGPickOnetoGO),1.0f); log("Btn_OK_TAG"); } …………………………………… }</span>
<span >//粒子播放方法,就是加载粒子的pList文件,然后添加进来,播放完毕后释放 。voID GameBaseScene::playParticle(Point point,char* pListname){ ParticleSystem* particleSystem_foot = ParticleSystemQuad::create(pListname); particleSystem_foot->retain(); ParticleBatchNode *batch = ParticleBatchNode::createWithTexture(particleSystem_foot->getTexture()); batch->addChild(particleSystem_foot); addChild(batch); particleSystem_foot->setposition( point + ccp(tileDWIDth/2,tiledHeight/2)); particleSystem_foot->release(); }</span>
效果如图
点击下载代码http://download.csdn.net/detail/lIDeguo1979/8315969
未完待续...................
总结以上是内存溢出为你收集整理的Cocos2d-x 3.2 大富翁游戏项目开发-第十四部分 购买空地动画全部内容,希望文章能够帮你解决Cocos2d-x 3.2 大富翁游戏项目开发-第十四部分 购买空地动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)