Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了23.cocos2d-x骨骼动画大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

温馨提示:
Tests-V3.8\tests\cpp-tests\resources\spine文件夹下有raptor.atlas、raptor.json、raptor.png文件


HelloWorldScene.h文件

#ifndef __HelLOWORLD_SCENE_H__ #define __HelLOWORLD_SCENE_H__ #include "cocos2d.h" class HelloWorld : public cocos2d::Layer { public: // there's no 'id' in cpp,so we recommend returning the class instance pointer static cocos2d::Scene* createScene(); // Here's a difference. Method 'init' in cocos2d-x returns bool,instead of returning 'id' in cocos2d-iphone virtual bool init(); // implement the "static create()" method manually CREATE_FUNC(HelloWorld); }; #endif // __HelLOWORLD_SCENE_H__ 

HelloWorldScene.cpp文件

#include "HelloWorldScene.h"
#include "cocostudio/Cocostudio.h"
#include "ui/CocosGUI.h"
#include "spine\spine.h"
#include <spine/spine-cocos2dx.h>

USING_NS_Cc;
using namespace spine;
using namespace cocostudio::timeline;

Scene* HelloWorld::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();

    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }

    auto rootNode = CSLoader::createNode("MainScene.csb");

    Vec2  visiable = Director::geTinstance()->getVisibleSize();
    auto skeletonNode = new SkeletonAnimation("raptor.json","raptor.atlas");
    skeletonNode->setPosition(Vec2(visiable.x /2,50));
    skeletonNode->setScale(0.5);
    //0.一个一个执行,过度时不会卡顿
    //skeletonNode->setMix("walk","gungrab",0.5f);
    //1.轨道、走路动作、是否循环
    skeletonNode->setAnimation(0,"walk",true);
    ////2.setAnimation方法只能播放一种动画,所以当要连续播放不同的动画时,需要使用addAnimation方法来实现,它可以一条一条的播放不同的动画。
    skeletonNode->setAnimation(1,"empty",false);
    skeletonNode->addAnimation(1,"gungrab",false,2);
    //3.动画的播放快慢
    skeletonNode->setTimeScale(0.5f);
    //4.是否显示骨骼
    skeletonNode->setDebugBonesEnabled(true);
    addChild(skeletonNodE);


    addChild(rootNodE);

    return true;
}

大佬总结

以上是大佬教程为你收集整理的23.cocos2d-x骨骼动画全部内容,希望文章能够帮你解决23.cocos2d-x骨骼动画所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。