![[cocos2dx学习笔记]用cocos2dx3.X完成塔防游戏王国保卫战--防御塔(三)之初级炮塔,第1张 [cocos2dx学习笔记]用cocos2dx3.X完成塔防游戏王国保卫战--防御塔(三)之初级炮塔,第1张](/aiimages/%5Bcocos2dx%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%5D%E7%94%A8cocos2dx3.X%E5%AE%8C%E6%88%90%E5%A1%94%E9%98%B2%E6%B8%B8%E6%88%8F%E7%8E%8B%E5%9B%BD%E4%BF%9D%E5%8D%AB%E6%88%98--%E9%98%B2%E5%BE%A1%E5%A1%94%EF%BC%88%E4%B8%89%EF%BC%89%E4%B9%8B%E5%88%9D%E7%BA%A7%E7%82%AE%E5%A1%94.png)
与箭塔相比,箭塔一共需要只需要1-2张图片,除了弓箭手,塔是静止的,而炮塔相对比较复杂
从图中我们可以看出,炮塔的动作序列比较复杂,所以只需要将一个个动画序列分清楚,好在我们用的现成的图片资源,只要一个个通过addchild添加进去即可,然后用动画序列播放。
首先重载shoot
voID BaseArtilleryTower::shoot(float dt){ checkNearestMonster(); if(nearestMonster!=NulL && nearestMonster->getCurrHp() > 0) { auto fireposition = nearestMonster->baseSprite->getposition() - this->getParent()->getposition(); runAction(Sequence::create( CallFuncN::create(CC_CALLBACK_0(BaseArtilleryTower::fireAnimation,this)),CallFuncN::create(CC_CALLBACK_0(BaseArtilleryTower::fire,this,fireposition)),NulL)); }}当射程范围内有敌人时,按顺序执行这个序列 先是左边的炮手蹲下并上抛这个动作,然后是炮d飞到炮筒的动画
voID BaseArtilleryTower::filledAnimation(){ leftShooter->runAction(Animate::create(AnimationCache::getInstance()->getAnimation(getname()+"leftShooter_throw"))); c4->runAction(Animate::create(AnimationCache::getInstance()->getAnimation(getname()+"c4")));}之后执行fire将炮d发射出去,基本原理和弓箭塔差不多,并且简单不少 voID BaseArtilleryTower::fire(Point fireposition){ auto currBullet = ArtilleryTowerBullet(); auto shootVector = fireposition; Point highPoint = Point(shootVector.x,shootVector.y+200); ccBezIErConfig bezIEr; bezIEr.controlPoint_1 = Point(currBullet->getposition().x,currBullet->getposition().y+200); bezIEr.controlPoint_2 = Point(shootVector.x,shootVector.y+200);; bezIEr.endposition = shootVector; float endRotate; if(shootVector.x>currBullet->getposition().x) endRotate = 180.0f; else endRotate = -180.0f; auto action = Spawn::create(BezIErTo::create(1.0f,bezIEr),Rotateto::create(1.0f,endRotate),NulL); currBullet->setBulletAction(action); currBullet->shoot(); runAction(Sequence::create(DelayTime::create(1.0f),CallFuncN::create(CC_CALLBACK_0(BaseArtilleryTower::filledAnimation,NulL)); currBullet = NulL;} filledAnimation是右边的炮手和炮筒的动画这里就省略了
其中炮d的动画与弓箭的动画区别就是旋转角度是转一圈,其他区别不大~
因为比较简单,这章就粗略介绍下
总结以上是内存溢出为你收集整理的[cocos2dx学习笔记]用cocos2dx3.X完成塔防游戏王国保卫战--防御塔(三)之初级炮塔全部内容,希望文章能够帮你解决[cocos2dx学习笔记]用cocos2dx3.X完成塔防游戏王国保卫战--防御塔(三)之初级炮塔所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)