add change play section test

This commit is contained in:
2youyou2 2014-06-17 15:57:30 +08:00
parent c221a59954
commit 806d74b6f9
4 changed files with 61 additions and 2 deletions

View File

@ -116,7 +116,6 @@ void ActionTimeline::gotoFrameAndPause(int startIndex)
_startFrame = _currentFrame = startIndex;
_time = _currentFrame * _frameInternal;
pause();
gotoFrame(_currentFrame);
}

View File

@ -97,10 +97,12 @@ public:
virtual void setDuration(int duration) { _duration = duration; }
virtual int getDuration() const { return _duration; }
/** Start frame index of this action*/
virtual int getStartFrame() const { return _startFrame; }
/** End frame of this action.
* When action play to this frame, if action is not loop, then it will stop,
* or it will play from start frame again. */
virtual void setEndFrame(int endFrame) { _endFrame = endFrame; }
virtual int getEndFrame() const { return _endFrame; }
/** Get current frame. */

View File

@ -22,6 +22,9 @@ Layer *CreateAnimationLayer(int index)
case TEST_ANIMATIONELEMENT:
pLayer = new TestActionTimeline();
break;
case TEST_CHANGE_PLAY_SECTION:
pLayer = new TestChangePlaySection();
break;
case TEST_TIMELINE_PERFORMACE:
pLayer = new TestTimelinePerformance();
break;
@ -181,6 +184,8 @@ void ActionTimelineTestLayer::backCallback(Ref *pSender)
s->release();
}
// TestActionTimeline
void TestActionTimeline::onEnter()
{
@ -206,6 +211,46 @@ std::string TestActionTimeline::title() const
}
// TestActionTimeline
void TestChangePlaySection::onEnter()
{
ActionTimelineTestLayer::onEnter();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("armature/Cowboy0.plist", "armature/Cowboy0.png");
Node* node = NodeReader::getInstance()->createNode("ActionTimeline/boy_1.ExportJson");
action = ActionTimelineCache::getInstance()->createAction("ActionTimeline/boy_1.ExportJson");
node->runAction(action);
action->gotoFrameAndPlay(70, action->getDuration(), true);
node->setScale(0.2f);
node->setPosition(150,100);
// add touch event listener
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(TestChangePlaySection::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
addChild(node);
}
std::string TestChangePlaySection::title() const
{
return "Test Change Play Section";
}
void TestChangePlaySection::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
if(action->getStartFrame() == 0)
action->gotoFrameAndPlay(70, action->getDuration(), true);
else
action->gotoFrameAndPlay(0, 60, true);
}
// TestTimelinePerformance
void TestTimelinePerformance::onEnter()
{

View File

@ -22,6 +22,7 @@ public:
enum {
TEST_ANIMATIONELEMENT = 0,
TEST_CHANGE_PLAY_SECTION,
TEST_TIMELINE_PERFORMACE,
TEST_ANIMATION_LAYER_COUNT
@ -55,6 +56,18 @@ public:
virtual std::string title() const override;
};
class TestChangePlaySection : public ActionTimelineTestLayer
{
public:
virtual void onEnter();
virtual std::string title() const override;
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
protected:
ActionTimeline* action;
};
class TestTimelinePerformance : public ActionTimelineTestLayer
{
public: