cpp-tests

This commit is contained in:
geron-cn 2014-06-18 18:11:21 +08:00
parent 5cfbd3a2bd
commit d2746f64a6
2 changed files with 118 additions and 1 deletions

View File

@ -1487,3 +1487,99 @@ void TestChangeAnimationInternal::onTouchesEnded(const std::vector<Touch*>& touc
Director::getInstance()->setAnimationInterval(1/30.0f);
}
}
//TestDirectFromBinay
const char* TestLoadFromBinary::m_binaryFilesNames[BINARYFILECOUNT] ={"armature/bear.csb","armature/horse.csb",
"armature/Cowboy.csb","armature/hero.csb",
"armature/HeroAnimation.csb","armature/testEasing.csb"};
const char* TestLoadFromBinary::m_armatureNames[BINARYFILECOUNT] ={"bear","horse",
"Cowboy","hero",
"HeroAnimation","testEasing"};
void TestLoadFromBinary::onEnter()
{
ArmatureTestLayer::onEnter();
//setTouchEnabled(true);
m_armatureIndex = -1; // none
// remove json created
// remove sync resource
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/bear.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo(m_binaryFilesNames[0]);
// load from binary
ArmatureDataManager::getInstance()->addArmatureFileInfo(m_binaryFilesNames[0]);
m_armature = Armature::create(m_armatureNames[0]);
m_armature->getAnimation()->playWithIndex(0);
m_armature->setScale(1.0f);
m_armature->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y));
addChild(m_armature);
}
std::string TestLoadFromBinary::title() const
{
return "Test load from binary file";
}
std::string TestLoadFromBinary::subtitle() const
{
return "direct load. \nTouch to change to Asynchronous load.";
}
void TestLoadFromBinary::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
// remove json created
// remove sync resource
if(-1 == m_armatureIndex )
{
ArmatureDataManager::getInstance()->removeArmatureFileInfo(m_binaryFilesNames[0]);
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/Cowboy.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/hero.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/horse.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/HeroAnimation.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/testEasing.ExportJson");
for( int i = 0; i < BINARYFILECOUNT; i++)
{
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync(m_binaryFilesNames[i], this, schedule_selector(TestLoadFromBinary::dataLoaded));
}
m_armatureIndex = -2; // is loading
}
else if(m_armatureIndex>=0 && m_armature != NULL)
{
this->removeChild(m_armature);
m_armatureIndex = m_armatureIndex==BINARYFILECOUNT-1 ? 0 : m_armatureIndex+1;
m_armature = Armature::create(m_armatureNames[m_armatureIndex]);
m_armature->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y));
if(m_armatureIndex == 2 ) // cowboy is 0.2
m_armature->setScale(0.2f);
m_armature->getAnimation()->playWithIndex(0);
addChild(m_armature);
}
}
void TestLoadFromBinary::dataLoaded( float percent )
{
LabelTTF *label = (LabelTTF *)getChildByTag(10001);
if (label)
{
char pszPercent[255];
sprintf(pszPercent, "%s %f", subtitle().c_str(), percent * 100);
label->setString(pszPercent);
}
if (percent >= 1)
{
label->setString("Touch to change armature");
m_armatureIndex = 0;
}
}

View File

@ -45,6 +45,7 @@ enum {
TEST_PLAY_SEVERAL_MOVEMENT,
TEST_EASING,
TEST_CHANGE_ANIMATION_INTERNAL,
TEST_DIRECT_FROM_BINARY,
TEST_LAYER_COUNT
};
@ -393,4 +394,24 @@ public:
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
};
#define BINARYFILECOUNT 6
class TestLoadFromBinary : public ArmatureTestLayer
{
public:
virtual void onEnter();
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
void dataLoaded(float percent);
private:
cocostudio::Armature *m_armature; // current armature
static const char* m_binaryFilesNames[BINARYFILECOUNT];
static const char* m_armatureNames[BINARYFILECOUNT];
int m_armatureIndex; // index of sync loaded armature, default -1 is none
};
#endif // __HELLOWORLD_SCENE_H__