mirror of https://github.com/axmolengine/axmol.git
change play arguments
This commit is contained in:
parent
7be834ea37
commit
324732b867
|
@ -57,6 +57,7 @@ ArmatureAnimation::ArmatureAnimation()
|
|||
, _ignoreFrameEvent(false)
|
||||
, _onMovementList(false)
|
||||
, _movementListLoop(false)
|
||||
, _movementListDurationTo(-1)
|
||||
, _userObject(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();
|
||||
_movementListLoop = loop;
|
||||
_movementListDurationTo = durationTo;
|
||||
_onMovementList = true;
|
||||
_movementIndex = 0;
|
||||
|
||||
for (int i = 0; i<movementNumber; i++)
|
||||
{
|
||||
_movementList.push_back(movementNames[i]);
|
||||
}
|
||||
_movementList = movementNames;
|
||||
|
||||
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();
|
||||
_movementListLoop = loop;
|
||||
_movementListDurationTo = durationTo;
|
||||
_onMovementList = true;
|
||||
_movementIndex = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -511,7 +511,7 @@ void ArmatureAnimation::updateMovementList()
|
|||
{
|
||||
if (_movementListLoop)
|
||||
{
|
||||
play(_movementList.at(_movementIndex).c_str(), -1, 0);
|
||||
play(_movementList.at(_movementIndex).c_str(), _movementListDurationTo, 0);
|
||||
_movementIndex++;
|
||||
|
||||
if (_movementIndex >= _movementList.size())
|
||||
|
@ -523,7 +523,7 @@ void ArmatureAnimation::updateMovementList()
|
|||
{
|
||||
if (_movementIndex < _movementList.size())
|
||||
{
|
||||
play(_movementList.at(_movementIndex).c_str(), -1, 0);
|
||||
play(_movementList.at(_movementIndex).c_str(), _movementListDurationTo, 0);
|
||||
_movementIndex++;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -132,8 +132,8 @@ public:
|
|||
virtual void playByIndex(int animationIndex, int durationTo = -1, int loop = -1);
|
||||
|
||||
|
||||
virtual void play(bool loop, const std::string *movementNames, int movementNumber);
|
||||
virtual void playByIndex(bool loop, const int *movementIndexes, int movementNumber);
|
||||
virtual void play(const std::vector<std::string>& movementNames, int durationTo = -1, bool loop = true);
|
||||
virtual void playByIndex(const std::vector<int>& movementIndexes, int durationTo = -1, bool loop = true);
|
||||
|
||||
/**
|
||||
* Go to specified frame and play current movement.
|
||||
|
@ -293,6 +293,7 @@ protected:
|
|||
bool _onMovementList;
|
||||
bool _movementListLoop;
|
||||
unsigned int _movementIndex;
|
||||
int _movementListDurationTo;
|
||||
|
||||
cocos2d::Object *_userObject;
|
||||
protected:
|
||||
|
|
|
@ -1360,13 +1360,15 @@ void TestPlaySeveralMovement::onEnter()
|
|||
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||
|
||||
std::string names[] = {"Walk", "FireMax", "Fire"};
|
||||
//int indexes[] = {0, 1, 2};
|
||||
std::string name[] = {"Walk", "FireMax", "Fire"};
|
||||
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::create("Cowboy");
|
||||
armature->getAnimation()->play(true, names, 3);
|
||||
//armature->getAnimation()->playByIndex(true, indexes, 3);
|
||||
armature->getAnimation()->play(names);
|
||||
// armature->getAnimation()->playByIndex(indexes);
|
||||
armature->setScale(0.2f);
|
||||
|
||||
armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y/*-100*/));
|
||||
|
|
Loading…
Reference in New Issue