change play arguments

This commit is contained in:
yinkaile 2013-12-18 23:29:54 +08:00
parent 7be834ea37
commit 324732b867
3 changed files with 19 additions and 16 deletions

View File

@ -57,6 +57,7 @@ ArmatureAnimation::ArmatureAnimation()
, _ignoreFrameEvent(false) , _ignoreFrameEvent(false)
, _onMovementList(false) , _onMovementList(false)
, _movementListLoop(false) , _movementListLoop(false)
, _movementListDurationTo(-1)
, _userObject(nullptr) , _userObject(nullptr)
, _movementEventCallFunc(nullptr) , _movementEventCallFunc(nullptr)
@ -256,33 +257,32 @@ void ArmatureAnimation::playByIndex(int animationIndex, int durationTo, int loop
} }
void ArmatureAnimation::play(bool loop, const std::string *movementNames, int movementNumber) void ArmatureAnimation::play(const std::vector<std::string>& movementNames, int durationTo, bool loop)
{ {
_movementList.clear(); _movementList.clear();
_movementListLoop = loop; _movementListLoop = loop;
_movementListDurationTo = durationTo;
_onMovementList = true; _onMovementList = true;
_movementIndex = 0; _movementIndex = 0;
for (int i = 0; i<movementNumber; i++) _movementList = movementNames;
{
_movementList.push_back(movementNames[i]);
}
updateMovementList(); updateMovementList();
} }
void ArmatureAnimation::playByIndex(bool loop, const int *movementIndexes, int movementNumber) void ArmatureAnimation::playByIndex(const std::vector<int>& movementIndexes, int durationTo, bool loop)
{ {
_movementList.clear(); _movementList.clear();
_movementListLoop = loop; _movementListLoop = loop;
_movementListDurationTo = durationTo;
_onMovementList = true; _onMovementList = true;
_movementIndex = 0; _movementIndex = 0;
std::vector<std::string> &movName = _animationData->movementNames; std::vector<std::string> &movName = _animationData->movementNames;
for (int i = 0; i<movementNumber; i++) for(auto& index : movementIndexes)
{ {
std::string name = movName.at(movementIndexes[i]); std::string name = movName.at(index);
_movementList.push_back(name); _movementList.push_back(name);
} }
@ -511,7 +511,7 @@ void ArmatureAnimation::updateMovementList()
{ {
if (_movementListLoop) if (_movementListLoop)
{ {
play(_movementList.at(_movementIndex).c_str(), -1, 0); play(_movementList.at(_movementIndex).c_str(), _movementListDurationTo, 0);
_movementIndex++; _movementIndex++;
if (_movementIndex >= _movementList.size()) if (_movementIndex >= _movementList.size())
@ -523,7 +523,7 @@ void ArmatureAnimation::updateMovementList()
{ {
if (_movementIndex < _movementList.size()) if (_movementIndex < _movementList.size())
{ {
play(_movementList.at(_movementIndex).c_str(), -1, 0); play(_movementList.at(_movementIndex).c_str(), _movementListDurationTo, 0);
_movementIndex++; _movementIndex++;
} }
else else

View File

@ -132,8 +132,8 @@ public:
virtual void playByIndex(int animationIndex, int durationTo = -1, int loop = -1); virtual void playByIndex(int animationIndex, int durationTo = -1, int loop = -1);
virtual void play(bool loop, const std::string *movementNames, int movementNumber); virtual void play(const std::vector<std::string>& movementNames, int durationTo = -1, bool loop = true);
virtual void playByIndex(bool loop, const int *movementIndexes, int movementNumber); virtual void playByIndex(const std::vector<int>& movementIndexes, int durationTo = -1, bool loop = true);
/** /**
* Go to specified frame and play current movement. * Go to specified frame and play current movement.
@ -293,6 +293,7 @@ protected:
bool _onMovementList; bool _onMovementList;
bool _movementListLoop; bool _movementListLoop;
unsigned int _movementIndex; unsigned int _movementIndex;
int _movementListDurationTo;
cocos2d::Object *_userObject; cocos2d::Object *_userObject;
protected: protected:

View File

@ -1360,13 +1360,15 @@ void TestPlaySeveralMovement::onEnter()
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this); listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
std::string names[] = {"Walk", "FireMax", "Fire"}; std::string name[] = {"Walk", "FireMax", "Fire"};
//int indexes[] = {0, 1, 2}; std::vector<std::string> names(name, name+3);
// int index[] = {0, 1, 2};
// std::vector<int> indexes(index, index+3);
Armature *armature = NULL; Armature *armature = NULL;
armature = Armature::create("Cowboy"); armature = Armature::create("Cowboy");
armature->getAnimation()->play(true, names, 3); armature->getAnimation()->play(names);
//armature->getAnimation()->playByIndex(true, indexes, 3); // armature->getAnimation()->playByIndex(indexes);
armature->setScale(0.2f); armature->setScale(0.2f);
armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y/*-100*/)); armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y/*-100*/));