mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Changed file loading to use cocos2d-x API.
This commit is contained in:
parent
17394e1851
commit
6addb86a40
6
.gitignore
vendored
6
.gitignore
vendored
@ -3,3 +3,9 @@ spine-sfml/Debug/*
|
|||||||
spine-libgdx/bin/*
|
spine-libgdx/bin/*
|
||||||
spine-libgdx/libs/*
|
spine-libgdx/libs/*
|
||||||
target
|
target
|
||||||
|
*Debug.win32*
|
||||||
|
*.sdf
|
||||||
|
*.opensdf
|
||||||
|
*.user
|
||||||
|
*.suo
|
||||||
|
spine-cocos2dx/cocos2dx
|
||||||
|
|||||||
10
spine-cocos2dx/.gitignore
vendored
10
spine-cocos2dx/.gitignore
vendored
@ -1,10 +0,0 @@
|
|||||||
*Debug.win32*
|
|
||||||
*.sdf
|
|
||||||
*.opensdf
|
|
||||||
*.user
|
|
||||||
*.suo
|
|
||||||
cocos2dx
|
|
||||||
spine-cocos2dx/include/spine/*
|
|
||||||
spine-cocos2dx/include/json/*
|
|
||||||
spine-cocos2dx/src/spine/*
|
|
||||||
spine-cocos2dx/src/json/*
|
|
||||||
@ -17,9 +17,7 @@ CCScene* ExampleScene::scene() {
|
|||||||
bool ExampleScene::init() {
|
bool ExampleScene::init() {
|
||||||
if (!CCLayer::init()) return false;
|
if (!CCLayer::init()) return false;
|
||||||
|
|
||||||
ifstream atlasFile("../data/spineboy.atlas");
|
Atlas *atlas = new Atlas("../data/spineboy.atlas");
|
||||||
Atlas *atlas = new Atlas(atlasFile);
|
|
||||||
|
|
||||||
SkeletonJson json(atlas);
|
SkeletonJson json(atlas);
|
||||||
SkeletonData *skeletonData = json.readSkeletonDataFile("../data/spineboy-skeleton.json");
|
SkeletonData *skeletonData = json.readSkeletonDataFile("../data/spineboy-skeleton.json");
|
||||||
Animation *animation = json.readAnimationFile("../data/spineboy-walk.json", skeletonData);
|
Animation *animation = json.readAnimationFile("../data/spineboy-walk.json", skeletonData);
|
||||||
|
|||||||
@ -50,9 +50,7 @@ public:
|
|||||||
|
|
||||||
class Atlas: public BaseAtlas {
|
class Atlas: public BaseAtlas {
|
||||||
public:
|
public:
|
||||||
Atlas (std::ifstream &file);
|
Atlas (const std::string &path);
|
||||||
Atlas (std::istream &input);
|
|
||||||
Atlas (const std::string &text);
|
|
||||||
Atlas (const char *begin, const char *end);
|
Atlas (const char *begin, const char *end);
|
||||||
|
|
||||||
AtlasRegion* findRegion (const std::string &name);
|
AtlasRegion* findRegion (const std::string &name);
|
||||||
|
|||||||
@ -37,6 +37,9 @@ public:
|
|||||||
SkeletonJson (Atlas *atlas);
|
SkeletonJson (Atlas *atlas);
|
||||||
/** The SkeletonJson owns the attachmentLoader. */
|
/** The SkeletonJson owns the attachmentLoader. */
|
||||||
SkeletonJson (BaseAttachmentLoader *attachmentLoader);
|
SkeletonJson (BaseAttachmentLoader *attachmentLoader);
|
||||||
|
|
||||||
|
SkeletonData* readSkeletonDataFile (const std::string &path) const;
|
||||||
|
Animation* readAnimationFile (const std::string &path, const SkeletonData *skeletonData) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace spine */
|
} /* namespace spine */
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include <spine-cocos2dx/Atlas.h>
|
#include <spine-cocos2dx/Atlas.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
|
|
||||||
@ -36,16 +37,12 @@ AtlasPage::~AtlasPage () {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
Atlas::Atlas (std::ifstream &file) {
|
Atlas::Atlas (const std::string &path) {
|
||||||
load(file);
|
unsigned long size;
|
||||||
}
|
char* data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData(
|
||||||
|
CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size));
|
||||||
Atlas::Atlas (std::istream &input) {
|
if (!data) throw std::runtime_error("Error reading atlas file: " + path);
|
||||||
load(input);
|
load(data, data + size);
|
||||||
}
|
|
||||||
|
|
||||||
Atlas::Atlas (const std::string &text) {
|
|
||||||
load(text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas::Atlas (const char *begin, const char *end) {
|
Atlas::Atlas (const char *begin, const char *end) {
|
||||||
|
|||||||
@ -24,7 +24,12 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include <spine-cocos2dx/SkeletonJson.h>
|
#include <spine-cocos2dx/SkeletonJson.h>
|
||||||
|
#include <stdexcept>
|
||||||
#include <spine-cocos2dx/AtlasAttachmentLoader.h>
|
#include <spine-cocos2dx/AtlasAttachmentLoader.h>
|
||||||
|
#include "platform/CCFileUtils.h"
|
||||||
|
|
||||||
|
using cocos2d::CCFileUtils;
|
||||||
|
using std::runtime_error;
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
@ -36,4 +41,20 @@ SkeletonJson::SkeletonJson (Atlas *atlas) :
|
|||||||
BaseSkeletonJson(new AtlasAttachmentLoader(atlas)) {
|
BaseSkeletonJson(new AtlasAttachmentLoader(atlas)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkeletonData* SkeletonJson::readSkeletonDataFile (const std::string &path) const {
|
||||||
|
unsigned long size;
|
||||||
|
char* data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData(
|
||||||
|
CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size));
|
||||||
|
if (!data) throw runtime_error("Error reading skeleton file: " + path);
|
||||||
|
return readSkeletonData(data, data + size);
|
||||||
|
}
|
||||||
|
|
||||||
|
Animation* SkeletonJson::readAnimationFile (const std::string &path, const SkeletonData *skeletonData) const {
|
||||||
|
unsigned long size;
|
||||||
|
char* data = reinterpret_cast<char*>(CCFileUtils::sharedFileUtils()->getFileData(
|
||||||
|
CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()).c_str(), "r", &size));
|
||||||
|
if (!data) throw runtime_error("Error reading animation file: " + path);
|
||||||
|
return readAnimation(data, data + size, skeletonData);
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace spine */
|
} /* namespace spine */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user