一、我們直接在COCOS2D-X自帶的HelloCpp的工程中添加代碼即可.我們在初始化中添加如下代碼:
[cpp]
CCSize szWin = CCDirector::sharedDirector()->getVisibleSize();
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("knight.png","knight.plist","knight.xml");//加載骨骼動畫文件
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("weapon.png","weapon.plist","weapon.xml");//加載骨骼動畫文件
setTouchEnabled(true);//開啓觸屏響應
pArmature = CCArmature::create("Knight_f/Knight");
pArmature->getAnimation()->playByIndex(0);//播放第一個動作
pArmature->setPosition(ccp(szWin.width/2-100,szWin.height/2));
pArmature->setScale(1.5f);
this->addChild(pArmature);
std::string sWeaponName[] = {"weapon_f-sword.png", "weapon_f-sword2.png", "weapon_f-sword3.png", "weapon_f-sword4.png", "weapon_f-sword5.png"};
CCSpriteDisplayData sprDisplayData;
for (int i=0;i<sizeof(sWeaponName)/sizeof(sWeaponName[0]);i++)
{
sprDisplayData.setParam(sWeaponName[i].c_str());
pArmature->getBone("weapon")->addDisplay(&sprDisplayData,i);
}
二、由於我們用到了COCOS2D-X中extensions中的類,故需要加入對應的目錄和相應的頭文件以及lib文件
①、在 工程->屬性->配置屬性->VC++目錄->包含目錄中添加extensions文件夾的路徑:$(SolutionDir)\extensions
②、添加頭文件、命名空間以及涉及的庫文件如下:
[cpp]
#include "CCArmature/utils/CCArmatureDataManager.h"
#include "CCArmature/CCArmature.h"
#pragma comment(lib,"libBox2d.lib")
#pragma comment(lib,"libExtensions.lib")
using namespace extension;
三、註冊觸屏分配器
[cpp]
void TestUseMutiplePicture::registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0, true);
}
三、響應觸屏事件以實現換裝.代碼如下:
[cpp]
bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
static int nDisplayIndex = -1;
++nDisplayIndex;
nDisplayIndex = (nDisplayIndex)%5;
pArmature->getBone("weapon")->changeDisplayByIndex(nDisplayIndex,true);
return false;
}
骨骼動畫換膚2
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
WPF中的DoubleAnimation
jackywei1987
2019-02-23 13:51:42
android studio集成極光推送
tlw90
2019-02-23 00:37:51
iOS 7:自定義導航轉場動畫以及更多
dragon_cao
2019-02-23 00:11:50
The import *** cannot be resolved
憤怒的列兵
2019-02-23 00:17:01
MyEclipse2014建立工程步驟筆記
westsky
2019-02-23 00:07:04
maven編譯工程時出現非法字符: \65279錯誤
fcl961561322
2019-02-23 00:05:51
postdrop: create file maildrop/xxx: Permission denied
lingping
2019-02-23 14:05:54
當您嘗試在 Outlook 中打開或保存電子郵件附件時出現錯誤消息:“無法創建文件
lingping
2019-02-23 14:05:54
連接查詢排序limit(join、order by、limit語句)
fdb2b
2019-02-23 14:01:03
關於數據庫的幾條常用操作
guokaikaikai
2019-02-23 13:32:01
MySQL使用索引優化DISTINCT操作
1415699306
2019-02-23 00:26:15
mysql數據庫改名的三種方法
李伯億
2019-02-23 00:14:25
Tomcat --> Cannot create a server using the selected type
小浩51
2019-02-23 00:02:03