mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Added debug rendering. Thanks to Stefan Nguyen @ Vinova Pte Ltd! http://www.vinova.sg
This commit is contained in:
parent
42d072ae8d
commit
81a9c60b20
@ -24,9 +24,10 @@ bool ExampleScene::init() {
|
|||||||
|
|
||||||
CCSkeleton* skeletonNode = new CCSkeleton(skeletonData);
|
CCSkeleton* skeletonNode = new CCSkeleton(skeletonData);
|
||||||
skeletonNode->state->setAnimation(animation, true);
|
skeletonNode->state->setAnimation(animation, true);
|
||||||
|
skeletonNode->debug = true;
|
||||||
|
|
||||||
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
|
CCSize windowSize = CCDirector::sharedDirector()->getWinSize();
|
||||||
skeletonNode->setPosition(ccp(winSize.width / 2, 20));
|
skeletonNode->setPosition(ccp(windowSize.width / 2, 20));
|
||||||
addChild(skeletonNode);
|
addChild(skeletonNode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -39,6 +39,7 @@ class CCSkeleton: public cocos2d::CCNode {
|
|||||||
public:
|
public:
|
||||||
Skeleton *skeleton;
|
Skeleton *skeleton;
|
||||||
AnimationState *state;
|
AnimationState *state;
|
||||||
|
bool debug;
|
||||||
|
|
||||||
CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData = 0);
|
CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData = 0);
|
||||||
virtual ~CCSkeleton ();
|
virtual ~CCSkeleton ();
|
||||||
|
|||||||
@ -25,15 +25,21 @@
|
|||||||
|
|
||||||
#include <spine-cocos2dx/CCSkeleton.h>
|
#include <spine-cocos2dx/CCSkeleton.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <spine/SkeletonData.h>
|
|
||||||
#include <spine-cocos2dx/Skeleton.h>
|
#include <spine-cocos2dx/Skeleton.h>
|
||||||
|
#include <spine-cocos2dx/RegionAttachment.h>
|
||||||
|
#include <spine/SkeletonData.h>
|
||||||
#include <spine/AnimationState.h>
|
#include <spine/AnimationState.h>
|
||||||
#include <spine/AnimationStateData.h>
|
#include <spine/AnimationStateData.h>
|
||||||
|
#include <spine/Slot.h>
|
||||||
|
#include <spine/BoneData.h>
|
||||||
|
#include <spine/Bone.h>
|
||||||
|
|
||||||
using namespace spine;
|
using namespace spine;
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
|
|
||||||
CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData) {
|
CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData) :
|
||||||
|
debug(false)
|
||||||
|
{
|
||||||
if (!skeletonData) throw std::invalid_argument("skeletonData cannot be null.");
|
if (!skeletonData) throw std::invalid_argument("skeletonData cannot be null.");
|
||||||
skeleton = new Skeleton(skeletonData);
|
skeleton = new Skeleton(skeletonData);
|
||||||
state = new AnimationState(stateData);
|
state = new AnimationState(stateData);
|
||||||
@ -58,4 +64,37 @@ void CCSkeleton::draw () {
|
|||||||
CC_NODE_DRAW_SETUP();
|
CC_NODE_DRAW_SETUP();
|
||||||
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
|
||||||
skeleton->draw();
|
skeleton->draw();
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
// Slots.
|
||||||
|
ccDrawColor4B(0, 0, 255, 10);
|
||||||
|
glLineWidth(1);
|
||||||
|
CCPoint points[4];
|
||||||
|
for (int i = 0, n = skeleton->slots.size(); i < n; i++) {
|
||||||
|
if (!skeleton->slots[i]->attachment) continue;
|
||||||
|
ccV3F_C4B_T2F_Quad quad = ((RegionAttachment*)skeleton->slots[i]->attachment)->quad;
|
||||||
|
points[0] = ccp(quad.bl.vertices.x, quad.bl.vertices.y);
|
||||||
|
points[1] = ccp(quad.br.vertices.x, quad.br.vertices.y);
|
||||||
|
points[2] = ccp(quad.tr.vertices.x, quad.tr.vertices.y);
|
||||||
|
points[3] = ccp(quad.tl.vertices.x, quad.tl.vertices.y);
|
||||||
|
ccDrawPoly(points, 4, true);
|
||||||
|
}
|
||||||
|
// Bone lengths.
|
||||||
|
glLineWidth(2);
|
||||||
|
ccDrawColor4B(255, 0, 0, 255);
|
||||||
|
for (int i = 0, n = skeleton->bones.size(); i < n; i++) {
|
||||||
|
Bone *bone = skeleton->bones[i];
|
||||||
|
float x = bone->data->length * bone->m00 + bone->worldX;
|
||||||
|
float y = bone->data->length * bone->m10 + bone->worldY;
|
||||||
|
ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y));
|
||||||
|
}
|
||||||
|
// Bone origins.
|
||||||
|
ccPointSize(4);
|
||||||
|
ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
|
||||||
|
for (int i = 0, n = skeleton->bones.size(); i < n; i++) {
|
||||||
|
Bone *bone = skeleton->bones[i];
|
||||||
|
ccDrawPoint(ccp(bone->worldX, bone->worldY));
|
||||||
|
if (i == 0) ccDrawColor4B(0, 255, 0, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user