首页 > 其他 > 详细

coco2d-x 之利用CocoStudio创建骨骼动画特别注意地方

时间:2014-03-14 06:26:13      阅读:773      评论:0      收藏:0      [点我收藏+]

最近的项目开始用CocoStudio来创建骨骼动画,在使用过程中发现CocoStudio中的骨骼动画还是挺好用的,在用的过程中发现有几个地方还是要比较注意的

骨骼动画的帧回调

我在使用中,一开始找这个回调设置的地方搞了很久,后面才发现如果要代码中要有帧回调,那么在界面的帧事件上一定要填写一下名称(如图):

bubuko.com,布布扣

bubuko.com,布布扣

就是这个帧事件就一定要填东西;

代码:

    armature = Armature::create("Cowboy");
    armature->getAnimation()->play("FireWithoutBullet");
    armature->getAnimation()->setSpeedScale(0.2f);
    armature->setScaleX(-0.2f);
    armature->setScaleY(0.2f);
    armature->setPosition(Point(VisibleRect::left().x + 70, VisibleRect::left().y));

    /*
    * Set armature‘s frame event callback function
    * To disconnect this event, just setFrameEventCallFunc(nullptr);
    */
    armature->getAnimation()->setFrameEventCallFunc(CC_CALLBACK_0(TestColliderDetector::onFrameEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
    addChild(armature);
void TestColliderDetector::onFrameEvent(Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
{
    CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt.c_str(), currentFrameIndex);

    /*
    * originFrameIndex is the frame index editted in Action Editor
    * currentFrameIndex is the current index animation played to
    * frame event may be delay emit, so originFrameIndex may be different from currentFrameIndex.
    */

    Point p = armature->getBone("Layer126")->getDisplayRenderNode()->convertToWorldSpaceAR(Point(0, 0));
    bullet->setPosition(Point(p.x + 60, p.y));

    bullet->stopAllActions();
    bullet->runAction(CCMoveBy::create(1.5f, Point(350, 0)));
}

这个动画就是很好的回调了

coco2d-x 之利用CocoStudio创建骨骼动画特别注意地方,布布扣,bubuko.com

coco2d-x 之利用CocoStudio创建骨骼动画特别注意地方

原文:http://blog.csdn.net/tian2kong/article/details/21159103

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!