mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 09:16:01 +08:00
Static method to create autoreleased CCSkeleton.
Example shows memory management. Fixed bug in memory management, texture not retained. :)
This commit is contained in:
parent
ec8509b511
commit
6342ed949e
@ -1,7 +1,6 @@
|
||||
#include "ExampleScene.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <spine-cocos2dx/spine.h>
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace spine;
|
||||
@ -9,21 +8,20 @@ using namespace std;
|
||||
|
||||
CCScene* ExampleScene::scene () {
|
||||
CCScene *scene = CCScene::create();
|
||||
ExampleScene *layer = ExampleScene::create();
|
||||
scene->addChild(layer);
|
||||
scene->addChild(ExampleScene::create());
|
||||
return scene;
|
||||
}
|
||||
|
||||
bool ExampleScene::init () {
|
||||
if (!CCLayer::init()) return false;
|
||||
|
||||
Atlas *atlas = new Atlas("spineboy.txt");
|
||||
atlas = new Atlas("spineboy.txt");
|
||||
SkeletonJson json(atlas);
|
||||
json.scale = 0.5;
|
||||
SkeletonData *skeletonData = json.readSkeletonData("spineboy-skeleton.json");
|
||||
Animation *animation = json.readAnimation("spineboy-walk.json", skeletonData);
|
||||
skeletonData = json.readSkeletonData("spineboy-skeleton.json");
|
||||
animation = json.readAnimation("spineboy-walk.json", skeletonData);
|
||||
|
||||
CCSkeleton* skeletonNode = new CCSkeleton(skeletonData);
|
||||
CCSkeleton* skeletonNode = CCSkeleton::create(skeletonData);
|
||||
skeletonNode->state->setAnimation(animation, true);
|
||||
skeletonNode->debug = true;
|
||||
|
||||
@ -33,3 +31,9 @@ bool ExampleScene::init () {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ExampleScene::~ExampleScene () {
|
||||
delete atlas;
|
||||
delete skeletonData;
|
||||
delete animation;
|
||||
}
|
||||
|
||||
@ -2,10 +2,17 @@
|
||||
#define _EXAMPLESCENE_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include <spine-cocos2dx/spine.h>
|
||||
|
||||
class ExampleScene: public cocos2d::CCLayer {
|
||||
private:
|
||||
spine::Atlas *atlas;
|
||||
spine::SkeletonData *skeletonData;
|
||||
spine::Animation *animation;
|
||||
|
||||
public:
|
||||
static cocos2d::CCScene* scene ();
|
||||
~ExampleScene ();
|
||||
|
||||
virtual bool init ();
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@ public:
|
||||
AnimationState *state;
|
||||
bool debug;
|
||||
|
||||
static CCSkeleton* CCSkeleton::create (SkeletonData* skeletonData);
|
||||
CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData = 0);
|
||||
virtual ~CCSkeleton ();
|
||||
|
||||
|
||||
@ -56,6 +56,7 @@ Atlas::Atlas (const char *begin, const char *end) {
|
||||
BaseAtlasPage* Atlas::newAtlasPage (const std::string &name) {
|
||||
AtlasPage *page = new AtlasPage();
|
||||
page->texture = CCTextureCache::sharedTextureCache()->addImage(name.c_str());
|
||||
page->texture->retain();
|
||||
page->atlas = CCTextureAtlas::createWithTexture(page->texture, 4);
|
||||
page->atlas->retain();
|
||||
return page;
|
||||
|
||||
@ -37,6 +37,12 @@
|
||||
using namespace spine;
|
||||
USING_NS_CC;
|
||||
|
||||
CCSkeleton* CCSkeleton::create (SkeletonData* skeletonData) {
|
||||
CCSkeleton* skeleton = new CCSkeleton(skeletonData);
|
||||
skeleton->autorelease();
|
||||
return skeleton;
|
||||
}
|
||||
|
||||
CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData) :
|
||||
debug(false) {
|
||||
if (!skeletonData) throw std::invalid_argument("skeletonData cannot be null.");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user