mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +08:00
Changed from New BSD to a custom license. The new license requires a Spine license to use the code. If you have a valid Spine license, you can do whatever you like with the code. This should not be a problem for anyone using the runtimes with Spine, nothing changes. If using the runtimes without a Spine license, you now need a Spine license. This is because the runtimes were created explicitly to be used with Spine.
55 lines
1.5 KiB
C++
55 lines
1.5 KiB
C++
|
|
|
|
#include "ExampleLayer.h"
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <string.h>
|
|
|
|
using namespace cocos2d;
|
|
using namespace spine;
|
|
using namespace std;
|
|
|
|
CCScene* ExampleLayer::scene () {
|
|
CCScene *scene = CCScene::create();
|
|
scene->addChild(ExampleLayer::create());
|
|
return scene;
|
|
}
|
|
|
|
bool ExampleLayer::init () {
|
|
if (!CCLayer::init()) return false;
|
|
|
|
skeletonNode = CCSkeletonAnimation::createWithFile("spineboy.json", "spineboy.atlas");
|
|
skeletonNode->setMix("walk", "jump", 0.2f);
|
|
skeletonNode->setMix("jump", "walk", 0.4f);
|
|
|
|
skeletonNode->setAnimation("walk", true);
|
|
// This shows how to setup animations to play back to back.
|
|
//skeletonNode->addAnimation("jump", true);
|
|
//skeletonNode->addAnimation("walk", true);
|
|
//skeletonNode->addAnimation("jump", true);
|
|
|
|
skeletonNode->timeScale = 0.3f;
|
|
skeletonNode->debugBones = true;
|
|
|
|
skeletonNode->runAction(CCRepeatForever::create(CCSequence::create(CCFadeOut::create(1),
|
|
CCFadeIn::create(1),
|
|
CCDelayTime::create(5),
|
|
NULL)));
|
|
|
|
CCSize windowSize = CCDirector::sharedDirector()->getWinSize();
|
|
skeletonNode->setPosition(ccp(windowSize.width / 2, 20));
|
|
addChild(skeletonNode);
|
|
|
|
scheduleUpdate();
|
|
|
|
return true;
|
|
}
|
|
|
|
void ExampleLayer::update (float deltaTime) {
|
|
if (skeletonNode->states[0]->loop) {
|
|
if (skeletonNode->states[0]->time > 2) skeletonNode->setAnimation("jump", false);
|
|
} else {
|
|
if (skeletonNode->states[0]->time > 1) skeletonNode->setAnimation("walk", true);
|
|
}
|
|
// if (skeletonNode->states[0]->time > 0.1) CCDirector::sharedDirector()->replaceScene(ExampleLayer::scene());
|
|
} |