From cfec4d5b7ef2c32a852fccb3321fc3bb811eadbe Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 19 Dec 2013 21:35:43 +0800 Subject: [PATCH] Updates spine test. --- cocos/editor-support/spine/spine-cocos2dx.cpp | 7 +- .../TestCpp/Classes/SpineTest/SpineTest.cpp | 77 ++++++++++++------- .../Cpp/TestCpp/Classes/SpineTest/SpineTest.h | 3 +- .../hd/spine/goblins.png.REMOVED.git-id | 1 + .../hd/spine/spineboy.png.REMOVED.git-id | 2 +- .../spine/goblins.png.REMOVED.git-id | 1 + 6 files changed, 58 insertions(+), 33 deletions(-) create mode 100644 samples/Cpp/TestCpp/Resources/hd/spine/goblins.png.REMOVED.git-id create mode 100644 samples/Cpp/TestCpp/Resources/spine/goblins.png.REMOVED.git-id diff --git a/cocos/editor-support/spine/spine-cocos2dx.cpp b/cocos/editor-support/spine/spine-cocos2dx.cpp index 8106a32fb9..8f895fcff4 100644 --- a/cocos/editor-support/spine/spine-cocos2dx.cpp +++ b/cocos/editor-support/spine/spine-cocos2dx.cpp @@ -45,7 +45,8 @@ void _spAtlasPage_createTexture (spAtlasPage* self, const char* path) { // self->width = texture->getPixelsWide(); // self->height = texture->getPixelsHigh(); self->width = texture->getContentSize().width; - self->height = texture->getContentSize().height;} + self->height = texture->getContentSize().height; +} void _spAtlasPage_disposeTexture (spAtlasPage* self) { ((TextureAtlas*)self->rendererObject)->release(); @@ -54,8 +55,8 @@ void _spAtlasPage_disposeTexture (spAtlasPage* self) { char* _spUtil_readFile (const char* path, int* length) { ssize_t size; char* data = reinterpret_cast( - FileUtils::getInstance()->getFileData( FileUtils::getInstance()->fullPathForFilename(path).c_str(), "r", &size)); - *length = size; + FileUtils::getInstance()->getFileData( FileUtils::getInstance()->fullPathForFilename(path).c_str(), "rb", &size)); + *length = static_cast(size); return data;} /**/ diff --git a/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.cpp b/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.cpp index 385be5b1c1..7d70a87640 100644 --- a/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.cpp +++ b/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.cpp @@ -47,36 +47,57 @@ void SpineTestScene::runThisTest() } bool SpineTestLayer::init () { - if (!Layer::init()) return false; - - skeletonNode = CCSkeletonAnimation::createWithFile("spine/spineboy.json", "spine/spineboy.atlas"); - skeletonNode->setMix("walk", "jump", 0.4f); - skeletonNode->setMix("jump", "walk", 0.4f); - skeletonNode->setAnimation("walk", true); - - skeletonNode->timeScale = 0.3f; - skeletonNode->debugBones = true; - - skeletonNode->runAction(RepeatForever::create(Sequence::create(FadeOut::create(1), - FadeIn::create(1), - DelayTime::create(5), - NULL))); - - Size windowSize = Director::getInstance()->getWinSize(); - skeletonNode->setPosition(Point(windowSize.width / 2, 20)); - addChild(skeletonNode); - - scheduleUpdate(); - - return true; + if (!Layer::init()) return false; + + skeletonNode = CCSkeletonAnimation::createWithFile("spine/spineboy.json", "spine/spineboy.atlas"); + skeletonNode->setMix("walk", "jump", 0.2f); + skeletonNode->setMix("jump", "walk", 0.4f); + + skeletonNode->setAnimationListener(this, animationStateEvent_selector(SpineTestLayer::animationStateEvent)); + skeletonNode->setAnimation(0, "walk", false); + skeletonNode->addAnimation(0, "jump", false); + skeletonNode->addAnimation(0, "walk", true); + skeletonNode->addAnimation(0, "jump", true, 4); + // skeletonNode->addAnimation(1, "drawOrder", true); + + skeletonNode->timeScale = 0.3f; + skeletonNode->debugBones = true; + skeletonNode->update(0); + + skeletonNode->runAction(CCRepeatForever::create(CCSequence::create(CCFadeOut::create(1), + CCFadeIn::create(1), + CCDelayTime::create(5), + NULL))); + + Size windowSize = Director::getInstance()->getWinSize(); + skeletonNode->setPosition(Point(windowSize.width / 2, 20)); + addChild(skeletonNode); + + scheduleUpdate(); + + return true; } void SpineTestLayer::update (float deltaTime) { - if (skeletonNode->states[0]->loop) { - if (skeletonNode->states[0]->time > 2) - skeletonNode->setAnimation("jump", false); - } else { - if (skeletonNode->states[0]->time > 1) - skeletonNode->setAnimation("walk", true); + +} + +void SpineTestLayer::animationStateEvent (CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount) { + spTrackEntry* entry = spAnimationState_getCurrent(node->state, trackIndex); + const char* animationName = (entry && entry->animation) ? entry->animation->name : 0; + + switch (type) { + case ANIMATION_START: + log("%d start: %s", trackIndex, animationName); + break; + case ANIMATION_END: + log("%d end: %s", trackIndex, animationName); + break; + case ANIMATION_COMPLETE: + log("%d complete: %s, %d", trackIndex, animationName, loopCount); + break; + case ANIMATION_EVENT: + log("%d event: %s, %s: %d, %f, %s", trackIndex, animationName, event->data->name, event->intValue, event->floatValue, event->stringValue); + break; } } diff --git a/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.h b/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.h index 58c4b13d0f..a5c9d83ddd 100644 --- a/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.h +++ b/samples/Cpp/TestCpp/Classes/SpineTest/SpineTest.h @@ -44,7 +44,8 @@ public: virtual bool init (); virtual void update (float deltaTime); - + void animationStateEvent (spine::CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount); + CREATE_FUNC (SpineTestLayer); }; diff --git a/samples/Cpp/TestCpp/Resources/hd/spine/goblins.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/spine/goblins.png.REMOVED.git-id new file mode 100644 index 0000000000..d816ff19d5 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/hd/spine/goblins.png.REMOVED.git-id @@ -0,0 +1 @@ +1d6f59e3732b50c100af321f566c36be2576714c \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/hd/spine/spineboy.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/hd/spine/spineboy.png.REMOVED.git-id index 6d319f3003..1cdca21ce6 100644 --- a/samples/Cpp/TestCpp/Resources/hd/spine/spineboy.png.REMOVED.git-id +++ b/samples/Cpp/TestCpp/Resources/hd/spine/spineboy.png.REMOVED.git-id @@ -1 +1 @@ -c22eca8f608170bab4ceb0086e48999fb2e3d32b \ No newline at end of file +c89eb3a469e797df40e9f119b16866acc040a9e0 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Resources/spine/goblins.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/spine/goblins.png.REMOVED.git-id new file mode 100644 index 0000000000..d816ff19d5 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/spine/goblins.png.REMOVED.git-id @@ -0,0 +1 @@ +1d6f59e3732b50c100af321f566c36be2576714c \ No newline at end of file