Adding Spine animation into cocos2d-x 3.10
from: cocos2d-x 3.13 tests/cpp-tests/Classes/SpineTest/SpineTest.cpp
To add Spine animation into cocos2d-x 3.10:
#include <spine/spine-cocos2dx.h> using namespace spine; ... bool SpineTestPerformanceLayer::init() { if (!SpineTestLayer::init()) return false; scheduleUpdate(); EventListenerTouchOneByOne* listener= EventListenerTouchOneByOne(); listener->onTouchBegan= [this](Touch* touch, Event* event) { Vec2 pos= convertToNodeSpace(touch->getLocation()); auto skeletonNode= SkeletonAnimation::createWithFile("spine/goblin.json", "spine/goblin.atlas", .6042f); // the scale .6042f affects atlas scale skeletonNode->setAnimation(0, "walk", true); skeletonNode->setSkin("goblin"); skeletonNode->setScale(.2f); // this scales the resulting node skeletonNode->setPosition(pos); addChild(skeletonNode); return true; }; _eventDispatcher->addEventListenerWithScreenGraphPriority(listener, this); return true; }
Even the spine nodes are added with the touch, the number of draw call does not increase. It seems like the Spine nodes are automatically batch processed.