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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值