版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、繼續(xù)上一篇文章繼續(xù)聊吧,這章內(nèi)容會比較多,也會附上代碼,很多朋友加了群,大家在群里面探討了很多東西,這讓大家都覺得受益匪淺,這便是極好的,廢話不多了,精靈是游戲的重要組成部分,那ARPG里面的精靈必然是要做得很細(xì)的,因為精靈要能動,能跑,能打,甚至要能做各種交互動作等等。 大家可以看一下下面的題,是精靈制作的流程思路: 上圖的人物素材來自于網(wǎng)絡(luò)流傳的夢幻西游,地圖還有其他素材是以前公司同事制作的,如果游戲正式上線,會換一套完整的自制的素材。圖中大家可以看到一個人物有很多部件組合而成,高端一點的游戲甚至部件多達(dá)幾十上百種,甚至做出骨骼動畫。不過以
2、我現(xiàn)在的做法是按照幀動畫方式實現(xiàn)各個人物的動作,人物的body部分細(xì)節(jié)處理會很多,還有大家看到圖中的字體(字體渲染描邊,我做的是最簡單的了,兩個LABEL合成在一起,效果能達(dá)到就行),由于人物要有方向,而且我們一次性就做8方向的人物動畫,那就需要8個方向的連幀圖片:首先,要組裝起來我們首先要建一個實體角色類,這個類里面不放別的,就統(tǒng)一放角色的部件屬性:類#ifndef _MAIN_ROLE_DATA_#define _MAIN_ROLE_DATA_ #include "cocos2d.h"#include "./Commen_ActionToDo.h"#
3、include "./Commen_Direction.h"USING_NS_CC;class MainRoledatapublic :/人物的TAGint tags;/人物姓名CCString* spiritname;/人物初始坐標(biāo)CCPoint nowpoint;/人物默認(rèn)像素圖CCString* spiritUrl;/人物站立像素圖路徑CCString* spiritUrl_zhan;/人物跑動像素圖路徑CCString* spiritUrl_pao;/人物攻擊像素圖路徑CCString* spiritUrl_attack;/人物施法像素圖路徑/增加人物BUFCCSt
4、ring* spiritUrl_magic;/人物站立最大幀int maxcut_zhan;/人物跑動最大幀int maxcut_pao;/人物戰(zhàn)斗最大幀int maxcut_attack;/人物施法最大幀int maxcut_magic;/人物當(dāng)前動作Commen_ActionToDo acttodo;/人物當(dāng)前朝向Commen_Direction dir;/動畫時間float actiontime;#endif枚舉幾個方向,和動作的類:enum Commen_Directionup=0,down=1,lefts=2,rigth=3,rigth_up=4,rigth_down=5,left_
5、down=6,left_up=7;enum Commen_ActionToDorun=1,stand=2,attack=3,death=4,funny=5,magicup=6;OK,然后配置精靈數(shù)據(jù),建了一個GetNPCData.cpp,GetNPCData.h,主要就是拿來初始化數(shù)據(jù),大致的思路是要將上面的Model填充數(shù)據(jù),相信大家能夠用很多種方式去實現(xiàn),填充數(shù)據(jù)(讀取XML配置文件,直接寫在代碼中配置);接下來我們正式組裝完整的八面玲瓏的精靈,建立,; 文件內(nèi)容如下:#ifndef _SPIRIT_PLAYER_#define _SPIRIT_PLAYER_ #include
6、"cocos2d.h"#include "./Commen_ActionToDo.h"#include "./Commen_Direction.h"#include "./GameData/MainRoledata.h"#include "./Commen/PublicShowUI.h"#include "./Effects/EffectsCommen.h"USING_NS_CC;class SpiritsPlayer : cocos2d:CCSprite public: C
7、CSprite* npc;CCSprite* yinzi;CCSprite* sp_liaotianbd;PublicShowUI* p_ui_name;CCArray *stringArray;CCAnimate* playdonghua;CCAnimate* playdonghua2;Commen_Direction move_dir;bool endflag;bool endflag2;bool thiszhujiao_flag;void Spirits_talkabout_hid(;SpiritsPlayer(MainRoledata roledata,int zOrder,bool
8、zhujiaoflag;SpiritsPlayer(void;CCAnimation* getNowAnt(MainRoledata roledata;CCAnimate* updateNowAnt(MainRoledata roledata;void updateNpcPoint(CCPoint newpoint;void moveTomap_dir(CCPoint newpoint;void moveTomap_move(int uestime,CCPoint newpoint,bool npcflag;/人物移動完成的回調(diào)void moveoverCallBack(void;/普通NPC
9、移動完成的回調(diào)void moveoverCallBackforNpc(void;/根據(jù)點擊坐標(biāo)獲得人物的朝向Commen_Direction getNowPointDir(CCPoint newpoint;/ 觸摸點是否在精靈上bool isTouchInside(CCPoint thisPos;/移動方式void movemethod(int uestime,CCPoint newpoint;private:/角色基本數(shù)據(jù)MainRoledata thisroledata;CCFiniteTimeAction *actall;CCActionInterval* act_moveto_zi;C
10、CActionInterval* act_moveto_npc;CCActionInterval* act_moveto_yinzi;CCActionInterval* act_moveto_eff;CCActionInterval* act_moveto_eff_zhujiao;CCFiniteTimeAction *actbackfun; int flag ;private:CCRect rect(;#endif/_SPIRIT_PLAYER_#include "./ImagePaths.h"#include "./GameData/GetNPCData.h&
11、quot;#include "./Commen/FontChina.h"SpiritsPlayer:SpiritsPlayer(MainRoledata roledata,int zOrder,bool zhujiaoflag/先初始化部分?jǐn)?shù)據(jù)thisroledata = roledata;act_moveto_zi =NULL;act_moveto_npc =NULL;act_moveto_yinzi =NULL;actall=NULL;thiszhujiao_flag = zhujiaoflag;p_ui_name = new PublicShowUI(;flag =
12、0;npc = SpiritsPlayer:create(roledata.spiritUrl->getCString(;if(npc=NULLCCLog("圖層路徑有誤,請檢查路徑"return;/設(shè)置NPC初始位置坐標(biāo)(該坐標(biāo)取決于當(dāng)前畫層)npc->setPosition(roledata.nowpoint;/NPC動畫設(shè)置playdonghua = SpiritsPlayer:updateNowAnt(roledata;npc->runAction(playdonghua;/*開始添加角色各部件*/添加角色名稱CCLabelTTF* label =
13、 CCLabelTTF:create(roledata.spiritname->getCString(, "微軟雅黑",12;label->setColor(ccWHITE;label->setDirty(true;label->setPosition(ccp(npc->getContentSize(.width/2,npc->getContentSize(.height+6;CCLabelTTF* labelback = CCLabelTTF:create(roledata.spiritname->getCString(, &qu
14、ot;微軟雅黑",12;labelback->setColor(ccBLACK;labelback->setDirty(true;labelback->setPosition(ccp(npc->getContentSize(.width/2+1,npc->getContentSize(.height+6-1;/添加NPC人物腳下陰影yinzi = CCSprite:create(p_yinzi;if(yinzi=NULLCCLog("圖層路徑有誤,請檢查路徑"return;if(zhujiaoflag=trueyinzi->se
15、tPosition(ccp(npc->getContentSize(.width/2,12;elseyinzi->setPosition(ccp(npc->getContentSize(.width/2,1;npc->addChild(yinzi,-1,110;npc->addChild(label,2,111;npc->addChild(labelback,1,112;cocos2d:CCRect SpiritsPlayer:rect(/獲取精靈區(qū)域大小return CCRectMake(npc->getPositionX(- npc->get
16、ContentSize(.width * npc->getAnchorPoint(.x,npc->getPositionY(-npc->getContentSize(.height* npc->getAnchorPoint(.y,npc->getContentSize(.width, npc->getContentSize(.height; bool SpiritsPlayer:isTouchInside(CCPoint thisPosCCPoint localPos = thisPos;CCRect rc = rect(;bool isTouched =
17、rc.containsPoint(localPos;if (isTouched = true CCLog(FontChina:G2U("觸發(fā)點擊"elseCCLog(FontChina:G2U("未點擊"return isTouched;void SpiritsPlayer:Spirits_talkabout_hid(CCLog(FontChina:G2U("*調(diào)用了*"CCAnimate* SpiritsPlayer:updateNowAnt(MainRoledata roledata/NPC動畫CCAnimation* dongh
18、ua = SpiritsPlayer:getNowAnt(roledata;if(roledata.actiontime>0donghuaroledata.maxcut_zhan;else donghua->setDelayPerUnit(/;/執(zhí)行默認(rèn)時間donghua->setRestoreOriginalFrame(true;donghua->setLoops(-1;CCAnimate* playdonghua = CCAnimate:create(donghua;return playdonghua;/* 主角位移移動*/void SpiritsPlayer:m
19、oveTomap_move(int uestime, CCPoint newpoint,bool npcflagif(npcflag=trueactbackfun = CCCallFunc:create(this, callfunc_selector(SpiritsPlayer:moveoverCallBackforNpc;elseactbackfun = CCCallFunc:create(this, callfunc_selector(SpiritsPlayer:moveoverCallBack;movemethod(uestime,newpoint;void SpiritsPlayer:
20、movemethod(int uestime,CCPoint newpointnpc->stopAction(actall;act_moveto_npc = CCMoveTo:create(uestime,ccp(newpoint.x,newpoint.y+20;actall = CCSequence:create(act_moveto_npc,actbackfun,NULL;npc->runAction(actall;/* 改變移動方向*/void SpiritsPlayer:moveTomap_dir(CCPoint newpointGetNPCData npcdata = G
21、etNPCData(;npcdata.GetNPCchapter1(;move_dir=SpiritsPlayer:getNowPointDir(newpoint;=move_dir;npcdata.role_player.acttodo = run;=;npc->stopAction(playdonghua;playdonghua = SpiritsPlayer:updateNowAnt(npcdata.role_player;npc->runAction(playdonghua;/* 根據(jù)點擊坐標(biāo)獲得人物的朝向*/Commen_Direction SpiritsPlayer:g
22、etNowPointDir(CCPoint newpointCommen_Direction thisdir = rigth_down; /默認(rèn)為右下/計算移動數(shù)據(jù)float center_x,center_y,npc_x,npc_y;int move_x,move_y;/更新NPC方向,狀態(tài)CCPoint origin = CCDirector:sharedDirector(->getVisibleOrigin(;CCSize size = CCDirector:sharedDirector(->getWinSize(;center_x 2;center_y 2;npc_x =
23、npc->getPositionX(;npc_y = npc->getPositionY(;move_x = (int(npc_x -newpoint.x ;move_y = (int(npc_y -newpoint.y - 20;if(move_x>=10&&move_y<=-10/左上thisdir = left_up;else if(move_x>=10&&move_y>=10/左下thisdir = left_down;else if(move_x<=-10&&move_y<=-10/右上t
24、hisdir = rigth_up;else if(move_x<=-10&&move_y>=10/右下thisdir =rigth_down;else if(move_x>-10&&move_x<10&&move_y>0/下thisdir =down;else if(move_x>-10&&move_x<10&&move_y<0/上thisdir =up;else if(move_x>0&&move_y>-10&&move
25、_y<10/左thisdir = lefts;else if(move_x<0&&move_y>-10&&move_y<10/右thisdir =rigth;return thisdir;/* 移動完成后的回調(diào)*/void SpiritsPlayer:moveoverCallBack(/移動完成之后恢復(fù)站立狀態(tài)GetNPCData npcdata = GetNPCData(;npcdata.GetNPCchapter1(;=move_dir;npcdata.role_player.acttodo = stand;=;npc->sto
26、pAction(playdonghua;playdonghua = SpiritsPlayer:updateNowAnt(npcdata.role_player;npc->runAction(playdonghua;/* 普通NPC移動完成后的回調(diào)*/void SpiritsPlayer:moveoverCallBackforNpc(/* 點擊瞬移至此*/void SpiritsPlayer:updateNpcPoint(CCPoint newpointp_ui_name->updataGameText(ccp(newpoint.x,newpoint.y+npc->getCo
27、ntentSize(.height/2+10;npc->setPosition(newpoint;yinzi->setPosition(ccp(newpoint.x,newpoint.y-npc->getContentSize(.height/2+5;/* 八方向人物動作合成器*/CCAnimation* SpiritsPlayer:getNowAnt(MainRoledata roledataCCAnimation* thisdonghua = CCAnimation:create(;switchcase up:switchcase run:for(int i = 0; i
28、<=roledata.maxcut_pao ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s06%03d.png",roledata.spiritUrl_pao->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case stand:for(int i = 0; i<=roledata.maxcut_zhan ; i+char donghuaurl100 = 0;sprintf(donghuaurl,&quo
29、t;%s06%03d.png",roledata.spiritUrl_zhan->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case attack:break;case death:break;case funny:break;default:break;break;case down:switchcase run:for(int i = 0; i<=roledata.maxcut_pao ; i+char donghuaurl100 = 0;sprintf(dong
30、huaurl,"%s04%03d.png",roledata.spiritUrl_pao->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case stand:for(int i = 0; i<=roledata.maxcut_zhan ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s04%03d.png",roledata.spiritUrl_zhan->getCString(,i;t
31、hisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case attack:break;case death:break;case funny:break;default:break;break;case lefts:switchcase run:for(int i = 0; i<=roledata.maxcut_pao ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s05%03d.png",roledata.spiritUrl_pao->getC
32、String(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case stand:for(int i = 0; i<=roledata.maxcut_zhan ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s05%03d.png",roledata.spiritUrl_zhan->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case
33、 attack:break;case death:break;case funny:break;default:break;break;case rigth:switchcase run:for(int i = 0; i<=roledata.maxcut_pao ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s07%03d.png",roledata.spiritUrl_pao->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl
34、;break;case stand:for(int i = 0; i<=roledata.maxcut_zhan ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s07%03d.png",roledata.spiritUrl_zhan->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case attack:break;case death:break;case funny:break;default:break;b
35、reak;case rigth_up:switchcase run:for(int i = 0; i<=roledata.maxcut_pao ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s03%03d.png",roledata.spiritUrl_pao->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case stand:for(int i = 0; i<=roledata.maxcut_zhan
36、; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s03%03d.png",roledata.spiritUrl_zhan->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case attack:for(int i = 0; i<=roledata.maxcut_attack ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s03%03d.png",
37、roledata.spiritUrl_attack->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case magicup:for(int i = 0; i<=roledata.maxcut_magic ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s03%03d.png",roledata.spiritUrl_magic->getCString(,i;thisdonghua->addSpriteF
38、rameWithFileName(donghuaurl;break;case death:break;case funny:break;default:break;break;case rigth_down:switchcase run:for(int i = 0; i<=roledata.maxcut_pao ; i+char donghuaurl1000 = 0;sprintf(donghuaurl,"%s00%03d.png",roledata.spiritUrl_pao->getCString(,i;thisdonghua->addSpriteFr
39、ameWithFileName(donghuaurl;break;case stand:for(int i = 0; i<=roledata.maxcut_zhan ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s00%03d.png",roledata.spiritUrl_zhan->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case attack:for(int i = 0; i<=roledata
40、.maxcut_attack ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s00%03d.png",roledata.spiritUrl_attack->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case magicup:for(int i = 0; i<=roledata.maxcut_magic ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s
41、00%03d.png",roledata.spiritUrl_magic->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case death:break;case funny:break;default:break;break;case left_down:switchcase run:for(int i = 0; i<=roledata.maxcut_pao ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s0
42、1%03d.png",roledata.spiritUrl_pao->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case stand:for(int i = 0; i<=roledata.maxcut_zhan ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s01%03d.png",roledata.spiritUrl_zhan->getCString(,i;thisdonghua->a
43、ddSpriteFrameWithFileName(donghuaurl;break;case attack:for(int i = 0; i<=roledata.maxcut_attack ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s01%03d.png",roledata.spiritUrl_attack->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case magicup:for(int i = 0
44、; i<=roledata.maxcut_magic ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s01%03d.png",roledata.spiritUrl_magic->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case death:break;case funny:break;default:break;break;case left_up:case run:for(int i = 0; i<
45、=roledata.maxcut_pao ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s02%03d.png",roledata.spiritUrl_pao->getCString(,i;thisdonghua->addSpriteFrameWithFileName(donghuaurl;break;case stand:for(int i = 0; i<=roledata.maxcut_zhan ; i+char donghuaurl100 = 0;sprintf(donghuaurl,"%s02%03d.png",roledata.spiritUrl_zhan->getCString(,i;thisdonghua-&g
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025屆陜西省安康市漢陰縣第二高級中學(xué)生物高二上期末質(zhì)量檢測模擬試題含解析
- 河北省邯鄲市永年區(qū)第二中學(xué)2025屆生物高三第一學(xué)期期末質(zhì)量檢測試題含解析
- 2024年影視拍攝合同范文
- 2025屆湖南省長沙雅禮中學(xué)高二上生物期末學(xué)業(yè)質(zhì)量監(jiān)測模擬試題含解析
- 2025屆內(nèi)蒙古通遼市科左后旗甘旗卡第二高級中學(xué)高一數(shù)學(xué)第一學(xué)期期末統(tǒng)考模擬試題含解析
- 山西省朔州市懷仁縣一中2025屆高一上數(shù)學(xué)期末調(diào)研模擬試題含解析
- 2025屆河北省承德二中高一數(shù)學(xué)第一學(xué)期期末學(xué)業(yè)水平測試試題含解析
- 2025屆云南省鎮(zhèn)沅縣第一中學(xué)生物高三第一學(xué)期期末考試模擬試題含解析
- 2025屆肇慶市高中畢業(yè)班生物高二上期末達(dá)標(biāo)檢測試題含解析
- 福建龍海市第二中學(xué)2025屆高二上數(shù)學(xué)期末調(diào)研試題含解析
- 工期及費(fèi)用索賠與反索賠操作指引
- 2023-2023年天津市和平區(qū)九年級上學(xué)期期中考試數(shù)學(xué)試卷
- 考綱知識點梳理梯形遞減表-高數(shù)文
- 2022星巴克大學(xué)咖啡大師認(rèn)證答案
- 立冬傳統(tǒng)節(jié)氣介紹PPT模板
- 《了凡四訓(xùn)》原文及譯文-拼音版
- 科幻畫教案設(shè)計
- YY/T 0321.2-2021一次性使用麻醉用針
- GB/T 26829-2011脈沖激光測距儀測距參數(shù)的室內(nèi)測試方法
- 鹽城介紹(英文)
- GB/T 15530.6-2008銅管折邊和銅合金對焊環(huán)松套鋼法蘭
評論
0/150
提交評論