这个问题解决了,原因是我在调用动画的时候也加了路径,导致无法播放,
应该将
ActionManager::shareManager()->playActionByName("Welcome/WelcomeUI.ExportJson","WelcomeAnimation");
改成
ActionManager::shareManager()->playActionByName("WelcomeUI.ExportJson","WelcomeAnimation");
即可。
问个问题,就是我在ui编辑器中制作动画,然后再代码中调用怎么调用都无法播放动画。
代码如下:
#include "WelcomeLayer.h"
#include "cocos-ext.h"
using namespace cocos2d::gui;
USING_NS_CC_EXT;
void WelcomeLayer::onEnter(){
CCLayer::onEnter();
}
void WelcomeLayer::onExit(){
m_UILayer->removeFromParent();
GUIReader::shareReader()->purge();
ActionManager::shareManager()->purge();
CCLayer::onExit();
}
bool WelcomeLayer::init(){
if(!CCLayer::init()){
return false;
}
m_UILayer = TouchGroup::create();
this->addChild(m_UILayer);
Layout* backgroundUI = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("Welcome/BackgroundUI.ExportJson"));
m_UILayer->addWidget(backgroundUI);
Layout* welcomeUI = dynamic_cast<Layout*>(GUIReader::shareReader()->widgetFromJsonFile("Welcome/WelcomeUI.ExportJson"));
m_UILayer->addWidget(welcomeUI);
UIButton* playBtn = static_cast<UIButton*>(m_UILayer->getWidgetByName("btn_play"));
playBtn->addTouchEventListener(this,toucheventselector(WelcomeLayer::startGame));
//播放动画
// ActionManager::shareManager()->playActionByName("Welcome/WelcomeUI.ExportJson","WelcomeAnimation");
//改成这个才能够播放动画
ActionManager::shareManager()->playActionByName("WelcomeUI.ExportJson","WelcomeAnimation");
return true;
}
void WelcomeLayer::startGame(CCObject* pSender,TouchEventType type){
if(type == TOUCH_EVENT_ENDED){
//进入游戏
}
}
我也参考了github的cocostudio的samples,都不行
https://github.com/chukong/CocoStudioSamples/blob/master/SampleUIAnimation/Classes/CocosGUIExamplesUIAnimationScene.cpp
求大神指教
附加后面写的也给demo,也是这样, TestUIAnimation.rar (546 KB)
