mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 02:36:56 +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 ();
|
||||||
|
|||||||
@ -1,39 +1,45 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2013, Esoteric Software
|
* Copyright (c) 2013, Esoteric Software
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
* list of conditions and the following disclaimer.
|
* list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#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