两个骨骼动画连接在一起,如何改变主角的在坐骑上的位置。我直接设置主角位置,主角就散架了:
代码:
void Hero::changeMount(Armature *horse)
{
if (horse == nullptr)
{
retain();
playWithIndex(0);
//Remove hero from display list
m_pMount->getBone("hero")->removeDisplay(0);
m_pMount->stopAllActions();
//Set position to current position
setPosition(m_pMount->getPosition());
//Add to layer
m_pLayer->addChild(this);
release();
setMount(horse);
}
else
{
setMount(horse);
retain();
//Remove from layer
removeFromParentAndCleanup(false);
//Get the hero bone
cocostudio::Bone *bone = horse->getBone("bone");
//Add hero as a display to this bone
bone->addDisplay(this, 0);
//Change this bone's display
bone->changeDisplayWithIndex(0, true);
bone->setIgnoreMovementBoneData(false);
setPosition(Vec2(0,0));
//Change animation
this->getAnimation()->play("riding");
setScale(1);
release();
}
}