[cocos2dx] Fix name clash with SkeletonRenderer, closes #2643

This commit is contained in:
Mario Zechner 2024-10-01 14:09:16 +02:00
parent c58d4c7522
commit 7461b08f36
9 changed files with 118 additions and 117 deletions

View File

@ -344,6 +344,7 @@
- `VertexEffect` has been removed. - `VertexEffect` has been removed.
### Cocos2d-x ### Cocos2d-x
- Renamed `SkeletonRenderer` to `SkeletonRendererCocos2dX` to avoid name clash with spine-cpp class.
### SFML ### SFML

View File

@ -62,7 +62,7 @@ bool SkeletonRendererSeparatorExample::init() {
// Spineboy's front, doesn't manage any skeleton, animation or GPU resources, but simply // Spineboy's front, doesn't manage any skeleton, animation or GPU resources, but simply
// renders the back slots of Spineboy. The skeleton, animatio state and GPU resources // renders the back slots of Spineboy. The skeleton, animatio state and GPU resources
// are shared with the front node! // are shared with the front node!
frontNode = SkeletonRenderer::createWithSkeleton(backNode->getSkeleton()); frontNode = SkeletonRendererCocos2dX::createWithSkeleton(backNode->getSkeleton());
frontNode->setSlotsRange(frontNode->findSlot("neck")->getData().getIndex(), -1); frontNode->setSlotsRange(frontNode->findSlot("neck")->getData().getIndex(), -1);
frontNode->setPosition(Vec2(_contentSize.width / 2, 20)); frontNode->setPosition(Vec2(_contentSize.width / 2, 20));

View File

@ -45,7 +45,7 @@ public:
private: private:
spine::SkeletonAnimation *backNode; spine::SkeletonAnimation *backNode;
spine::SkeletonRenderer *frontNode; spine::SkeletonRendererCocos2dX *frontNode;
cocos2d::DrawNode *betweenNode; cocos2d::DrawNode *betweenNode;
}; };

View File

@ -2,44 +2,44 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>English</string> <string>English</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>${PROJECT_NAME}</string> <string>${PROJECT_NAME}</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string> <string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key> <key>CFBundleIconFile</key>
<string>Icon-57.png</string> <string>Icon-57.png</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>com.esotericsoftware.spine</string> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundleName</key> <key>CFBundleName</key>
<string>${PROJECT_NAME}</string> <string>${PROJECT_NAME}</string>
<key>CFBundleShortVersionString</key> <key>CFBundlePackageType</key>
<string>1.0</string> <string>APPL</string>
<key>CFBundlePackageType</key> <key>CFBundleShortVersionString</key>
<string>APPL</string> <string>1.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1</string> <string>1</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>UIAppFonts</key> <key>NSHumanReadableCopyright</key>
<array/> <string>Copyright © 2019. All rights reserved.</string>
<key>UILaunchStoryboardName</key> <key>UIAppFonts</key>
<string>LaunchScreen</string> <array/>
<key>UIPrerenderedIcon</key> <key>UILaunchStoryboardName</key>
<true/> <string>LaunchScreen</string>
<key>UIStatusBarHidden</key> <key>UIPrerenderedIcon</key>
<true/> <true/>
<key>UISupportedInterfaceOrientations</key> <key>UIStatusBarHidden</key>
<array> <true/>
<string>UIInterfaceOrientationLandscapeRight</string> <key>UISupportedInterfaceOrientations</key>
<string>UIInterfaceOrientationLandscapeLeft</string> <array>
</array> <string>UIInterfaceOrientationLandscapeRight</string>
<key>NSHumanReadableCopyright</key> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>Copyright © 2019. All rights reserved.</string> </array>
</dict> </dict>
</plist> </plist>

View File

@ -121,7 +121,7 @@ namespace spine {
} }
SkeletonAnimation::SkeletonAnimation() SkeletonAnimation::SkeletonAnimation()
: SkeletonRenderer() { : SkeletonRendererCocos2dX() {
} }
SkeletonAnimation::~SkeletonAnimation() { SkeletonAnimation::~SkeletonAnimation() {

View File

@ -48,7 +48,7 @@ namespace spine {
/** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be /** Draws an animated skeleton, providing an AnimationState for applying one or more animations and queuing animations to be
* played later. */ * played later. */
class SkeletonAnimation : public SkeletonRenderer { class SkeletonAnimation : public SkeletonRendererCocos2dX {
public: public:
CREATE_FUNC(SkeletonAnimation); CREATE_FUNC(SkeletonAnimation);
static SkeletonAnimation *createWithData(SkeletonData *skeletonData, bool ownsSkeletonData = false); static SkeletonAnimation *createWithData(SkeletonData *skeletonData, bool ownsSkeletonData = false);
@ -125,7 +125,7 @@ namespace spine {
UpdateWorldTransformsListener _postUpdateListener; UpdateWorldTransformsListener _postUpdateListener;
private: private:
typedef SkeletonRenderer super; typedef SkeletonRendererCocos2dX super;
}; };
}// namespace spine }// namespace spine

View File

@ -62,31 +62,31 @@ namespace spine {
#define VLA_FREE(arr) #define VLA_FREE(arr)
#endif #endif
SkeletonRenderer *SkeletonRenderer::createWithSkeleton(Skeleton *skeleton, bool ownsSkeleton, bool ownsSkeletonData) { SkeletonRendererCocos2dX *SkeletonRendererCocos2dX::createWithSkeleton(Skeleton *skeleton, bool ownsSkeleton, bool ownsSkeletonData) {
SkeletonRenderer *node = new SkeletonRenderer(skeleton, ownsSkeleton, ownsSkeletonData); SkeletonRendererCocos2dX *node = new SkeletonRendererCocos2dX(skeleton, ownsSkeleton, ownsSkeletonData);
node->autorelease(); node->autorelease();
return node; return node;
} }
SkeletonRenderer *SkeletonRenderer::createWithData(SkeletonData *skeletonData, bool ownsSkeletonData) { SkeletonRendererCocos2dX *SkeletonRendererCocos2dX::createWithData(SkeletonData *skeletonData, bool ownsSkeletonData) {
SkeletonRenderer *node = new SkeletonRenderer(skeletonData, ownsSkeletonData); SkeletonRendererCocos2dX *node = new SkeletonRendererCocos2dX(skeletonData, ownsSkeletonData);
node->autorelease(); node->autorelease();
return node; return node;
} }
SkeletonRenderer *SkeletonRenderer::createWithFile(const std::string &skeletonDataFile, Atlas *atlas, float scale) { SkeletonRendererCocos2dX *SkeletonRendererCocos2dX::createWithFile(const std::string &skeletonDataFile, Atlas *atlas, float scale) {
SkeletonRenderer *node = new SkeletonRenderer(skeletonDataFile, atlas, scale); SkeletonRendererCocos2dX *node = new SkeletonRendererCocos2dX(skeletonDataFile, atlas, scale);
node->autorelease(); node->autorelease();
return node; return node;
} }
SkeletonRenderer *SkeletonRenderer::createWithFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale) { SkeletonRendererCocos2dX *SkeletonRendererCocos2dX::createWithFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale) {
SkeletonRenderer *node = new SkeletonRenderer(skeletonDataFile, atlasFile, scale); SkeletonRendererCocos2dX *node = new SkeletonRendererCocos2dX(skeletonDataFile, atlasFile, scale);
node->autorelease(); node->autorelease();
return node; return node;
} }
void SkeletonRenderer::initialize() { void SkeletonRendererCocos2dX::initialize() {
_clipper = new (__FILE__, __LINE__) SkeletonClipping(); _clipper = new (__FILE__, __LINE__) SkeletonClipping();
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
@ -98,7 +98,7 @@ namespace spine {
_skeleton->updateWorldTransform(Physics_Update); _skeleton->updateWorldTransform(Physics_Update);
} }
void SkeletonRenderer::setupGLProgramState(bool twoColorTintEnabled) { void SkeletonRendererCocos2dX::setupGLProgramState(bool twoColorTintEnabled) {
#if COCOS2D_VERSION < 0x00040000 #if COCOS2D_VERSION < 0x00040000
if (twoColorTintEnabled) { if (twoColorTintEnabled) {
setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState()); setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState());
@ -109,36 +109,36 @@ namespace spine {
#endif #endif
} }
void SkeletonRenderer::setSkeletonData(SkeletonData *skeletonData, bool ownsSkeletonData) { void SkeletonRendererCocos2dX::setSkeletonData(SkeletonData *skeletonData, bool ownsSkeletonData) {
_skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData); _skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData);
_ownsSkeletonData = ownsSkeletonData; _ownsSkeletonData = ownsSkeletonData;
} }
SkeletonRenderer::SkeletonRenderer() SkeletonRendererCocos2dX::SkeletonRendererCocos2dX()
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) { : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
} }
SkeletonRenderer::SkeletonRenderer(Skeleton *skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) SkeletonRendererCocos2dX::SkeletonRendererCocos2dX(Skeleton *skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas)
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) { : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData, ownsAtlas); initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData, ownsAtlas);
} }
SkeletonRenderer::SkeletonRenderer(SkeletonData *skeletonData, bool ownsSkeletonData) SkeletonRendererCocos2dX::SkeletonRendererCocos2dX(SkeletonData *skeletonData, bool ownsSkeletonData)
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) { : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
initWithData(skeletonData, ownsSkeletonData); initWithData(skeletonData, ownsSkeletonData);
} }
SkeletonRenderer::SkeletonRenderer(const std::string &skeletonDataFile, Atlas *atlas, float scale) SkeletonRendererCocos2dX::SkeletonRendererCocos2dX(const std::string &skeletonDataFile, Atlas *atlas, float scale)
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) { : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
initWithJsonFile(skeletonDataFile, atlas, scale); initWithJsonFile(skeletonDataFile, atlas, scale);
} }
SkeletonRenderer::SkeletonRenderer(const std::string &skeletonDataFile, const std::string &atlasFile, float scale) SkeletonRendererCocos2dX::SkeletonRendererCocos2dX(const std::string &skeletonDataFile, const std::string &atlasFile, float scale)
: _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) { : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _startSlotIndex(0), _endSlotIndex(std::numeric_limits<int>::max()) {
initWithJsonFile(skeletonDataFile, atlasFile, scale); initWithJsonFile(skeletonDataFile, atlasFile, scale);
} }
SkeletonRenderer::~SkeletonRenderer() { SkeletonRendererCocos2dX::~SkeletonRendererCocos2dX() {
if (_ownsSkeletonData) delete _skeleton->getData(); if (_ownsSkeletonData) delete _skeleton->getData();
if (_ownsSkeleton) delete _skeleton; if (_ownsSkeleton) delete _skeleton;
if (_ownsAtlas && _atlas) delete _atlas; if (_ownsAtlas && _atlas) delete _atlas;
@ -146,7 +146,7 @@ namespace spine {
delete _clipper; delete _clipper;
} }
void SkeletonRenderer::initWithSkeleton(Skeleton *skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) { void SkeletonRendererCocos2dX::initWithSkeleton(Skeleton *skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) {
_skeleton = skeleton; _skeleton = skeleton;
_ownsSkeleton = ownsSkeleton; _ownsSkeleton = ownsSkeleton;
_ownsSkeletonData = ownsSkeletonData; _ownsSkeletonData = ownsSkeletonData;
@ -154,13 +154,13 @@ namespace spine {
initialize(); initialize();
} }
void SkeletonRenderer::initWithData(SkeletonData *skeletonData, bool ownsSkeletonData) { void SkeletonRendererCocos2dX::initWithData(SkeletonData *skeletonData, bool ownsSkeletonData) {
_ownsSkeleton = true; _ownsSkeleton = true;
setSkeletonData(skeletonData, ownsSkeletonData); setSkeletonData(skeletonData, ownsSkeletonData);
initialize(); initialize();
} }
void SkeletonRenderer::initWithJsonFile(const std::string &skeletonDataFile, Atlas *atlas, float scale) { void SkeletonRendererCocos2dX::initWithJsonFile(const std::string &skeletonDataFile, Atlas *atlas, float scale) {
_atlas = atlas; _atlas = atlas;
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
@ -175,7 +175,7 @@ namespace spine {
initialize(); initialize();
} }
void SkeletonRenderer::initWithJsonFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale) { void SkeletonRendererCocos2dX::initWithJsonFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale) {
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true); _atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true);
CCASSERT(_atlas, "Error reading atlas file."); CCASSERT(_atlas, "Error reading atlas file.");
@ -193,7 +193,7 @@ namespace spine {
initialize(); initialize();
} }
void SkeletonRenderer::initWithBinaryFile(const std::string &skeletonDataFile, Atlas *atlas, float scale) { void SkeletonRendererCocos2dX::initWithBinaryFile(const std::string &skeletonDataFile, Atlas *atlas, float scale) {
_atlas = atlas; _atlas = atlas;
_attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas);
@ -207,7 +207,7 @@ namespace spine {
initialize(); initialize();
} }
void SkeletonRenderer::initWithBinaryFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale) { void SkeletonRendererCocos2dX::initWithBinaryFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale) {
_atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true); _atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true);
CCASSERT(_atlas, "Error reading atlas file."); CCASSERT(_atlas, "Error reading atlas file.");
@ -225,11 +225,11 @@ namespace spine {
} }
void SkeletonRenderer::update(float deltaTime) { void SkeletonRendererCocos2dX::update(float deltaTime) {
Node::update(deltaTime); Node::update(deltaTime);
} }
void SkeletonRenderer::draw(Renderer *renderer, const Mat4 &transform, uint32_t transformFlags) { void SkeletonRendererCocos2dX::draw(Renderer *renderer, const Mat4 &transform, uint32_t transformFlags) {
// Early exit if the skeleton is invisible. // Early exit if the skeleton is invisible.
if (getDisplayedOpacity() == 0 || _skeleton->getColor().a == 0) { if (getDisplayedOpacity() == 0 || _skeleton->getColor().a == 0) {
return; return;
@ -519,7 +519,7 @@ namespace spine {
if (!sibling) { if (!sibling) {
lastTwoColorTrianglesCommand->setForceFlush(true); lastTwoColorTrianglesCommand->setForceFlush(true);
} else { } else {
SkeletonRenderer *siblingSkeleton = dynamic_cast<SkeletonRenderer *>(sibling); SkeletonRendererCocos2dX *siblingSkeleton = dynamic_cast<SkeletonRendererCocos2dX *>(sibling);
if (!siblingSkeleton || // flush is next sibling isn't a SkeletonRenderer if (!siblingSkeleton || // flush is next sibling isn't a SkeletonRenderer
!siblingSkeleton->isTwoColorTint() || // flush if next sibling isn't two color tinted !siblingSkeleton->isTwoColorTint() || // flush if next sibling isn't two color tinted
!siblingSkeleton->isVisible() || // flush if next sibling is two color tinted but not visible !siblingSkeleton->isVisible() || // flush if next sibling is two color tinted but not visible
@ -538,7 +538,7 @@ namespace spine {
} }
void SkeletonRenderer::drawDebug(Renderer *renderer, const Mat4 &transform, uint32_t transformFlags) { void SkeletonRendererCocos2dX::drawDebug(Renderer *renderer, const Mat4 &transform, uint32_t transformFlags) {
#if !defined(USE_MATRIX_STACK_PROJECTION_ONLY) #if !defined(USE_MATRIX_STACK_PROJECTION_ONLY)
Director *director = Director::getInstance(); Director *director = Director::getInstance();
@ -658,7 +658,7 @@ namespace spine {
#endif #endif
} }
cocos2d::Rect SkeletonRenderer::getBoundingBox() const { cocos2d::Rect SkeletonRendererCocos2dX::getBoundingBox() const {
const int coordCount = computeTotalCoordCount(*_skeleton, _startSlotIndex, _endSlotIndex); const int coordCount = computeTotalCoordCount(*_skeleton, _startSlotIndex, _endSlotIndex);
if (coordCount == 0) return {0, 0, 0, 0}; if (coordCount == 0) return {0, 0, 0, 0};
VLA(float, worldCoords, coordCount); VLA(float, worldCoords, coordCount);
@ -670,57 +670,57 @@ namespace spine {
// --- Convenience methods for Skeleton_* functions. // --- Convenience methods for Skeleton_* functions.
void SkeletonRenderer::updateWorldTransform(Physics physics) { void SkeletonRendererCocos2dX::updateWorldTransform(Physics physics) {
_skeleton->updateWorldTransform(physics); _skeleton->updateWorldTransform(physics);
} }
void SkeletonRenderer::setToSetupPose() { void SkeletonRendererCocos2dX::setToSetupPose() {
_skeleton->setToSetupPose(); _skeleton->setToSetupPose();
} }
void SkeletonRenderer::setBonesToSetupPose() { void SkeletonRendererCocos2dX::setBonesToSetupPose() {
_skeleton->setBonesToSetupPose(); _skeleton->setBonesToSetupPose();
} }
void SkeletonRenderer::setSlotsToSetupPose() { void SkeletonRendererCocos2dX::setSlotsToSetupPose() {
_skeleton->setSlotsToSetupPose(); _skeleton->setSlotsToSetupPose();
} }
Bone *SkeletonRenderer::findBone(const std::string &boneName) const { Bone *SkeletonRendererCocos2dX::findBone(const std::string &boneName) const {
return _skeleton->findBone(boneName.c_str()); return _skeleton->findBone(boneName.c_str());
} }
Slot *SkeletonRenderer::findSlot(const std::string &slotName) const { Slot *SkeletonRendererCocos2dX::findSlot(const std::string &slotName) const {
return _skeleton->findSlot(slotName.c_str()); return _skeleton->findSlot(slotName.c_str());
} }
void SkeletonRenderer::setSkin(const std::string &skinName) { void SkeletonRendererCocos2dX::setSkin(const std::string &skinName) {
_skeleton->setSkin(skinName.empty() ? 0 : skinName.c_str()); _skeleton->setSkin(skinName.empty() ? 0 : skinName.c_str());
} }
void SkeletonRenderer::setSkin(const char *skinName) { void SkeletonRendererCocos2dX::setSkin(const char *skinName) {
_skeleton->setSkin(skinName); _skeleton->setSkin(skinName);
} }
Attachment *SkeletonRenderer::getAttachment(const std::string &slotName, const std::string &attachmentName) const { Attachment *SkeletonRendererCocos2dX::getAttachment(const std::string &slotName, const std::string &attachmentName) const {
return _skeleton->getAttachment(slotName.c_str(), attachmentName.c_str()); return _skeleton->getAttachment(slotName.c_str(), attachmentName.c_str());
} }
bool SkeletonRenderer::setAttachment(const std::string &slotName, const std::string &attachmentName) { bool SkeletonRendererCocos2dX::setAttachment(const std::string &slotName, const std::string &attachmentName) {
bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()) ? true : false; bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()) ? true : false;
_skeleton->setAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()); _skeleton->setAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str());
return result; return result;
} }
bool SkeletonRenderer::setAttachment(const std::string &slotName, const char *attachmentName) { bool SkeletonRendererCocos2dX::setAttachment(const std::string &slotName, const char *attachmentName) {
bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName) ? true : false; bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName) ? true : false;
_skeleton->setAttachment(slotName.c_str(), attachmentName); _skeleton->setAttachment(slotName.c_str(), attachmentName);
return result; return result;
} }
void SkeletonRenderer::setTwoColorTint(bool enabled) { void SkeletonRendererCocos2dX::setTwoColorTint(bool enabled) {
#if COCOS2D_VERSION >= 0x00040000 #if COCOS2D_VERSION >= 0x00040000
_twoColorTint = enabled; _twoColorTint = enabled;
#endif #endif
setupGLProgramState(enabled); setupGLProgramState(enabled);
} }
bool SkeletonRenderer::isTwoColorTint() { bool SkeletonRendererCocos2dX::isTwoColorTint() {
#if COCOS2D_VERSION < 0x00040000 #if COCOS2D_VERSION < 0x00040000
return getGLProgramState() == SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState(); return getGLProgramState() == SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState();
#else #else
@ -728,52 +728,52 @@ namespace spine {
#endif #endif
} }
void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) { void SkeletonRendererCocos2dX::setSlotsRange(int startSlotIndex, int endSlotIndex) {
_startSlotIndex = startSlotIndex == -1 ? 0 : startSlotIndex; _startSlotIndex = startSlotIndex == -1 ? 0 : startSlotIndex;
_endSlotIndex = endSlotIndex == -1 ? std::numeric_limits<int>::max() : endSlotIndex; _endSlotIndex = endSlotIndex == -1 ? std::numeric_limits<int>::max() : endSlotIndex;
} }
Skeleton *SkeletonRenderer::getSkeleton() const { Skeleton *SkeletonRendererCocos2dX::getSkeleton() const {
return _skeleton; return _skeleton;
} }
void SkeletonRenderer::setTimeScale(float scale) { void SkeletonRendererCocos2dX::setTimeScale(float scale) {
_timeScale = scale; _timeScale = scale;
} }
float SkeletonRenderer::getTimeScale() const { float SkeletonRendererCocos2dX::getTimeScale() const {
return _timeScale; return _timeScale;
} }
void SkeletonRenderer::setDebugSlotsEnabled(bool enabled) { void SkeletonRendererCocos2dX::setDebugSlotsEnabled(bool enabled) {
_debugSlots = enabled; _debugSlots = enabled;
} }
bool SkeletonRenderer::getDebugSlotsEnabled() const { bool SkeletonRendererCocos2dX::getDebugSlotsEnabled() const {
return _debugSlots; return _debugSlots;
} }
void SkeletonRenderer::setDebugBonesEnabled(bool enabled) { void SkeletonRendererCocos2dX::setDebugBonesEnabled(bool enabled) {
_debugBones = enabled; _debugBones = enabled;
} }
bool SkeletonRenderer::getDebugBonesEnabled() const { bool SkeletonRendererCocos2dX::getDebugBonesEnabled() const {
return _debugBones; return _debugBones;
} }
void SkeletonRenderer::setDebugMeshesEnabled(bool enabled) { void SkeletonRendererCocos2dX::setDebugMeshesEnabled(bool enabled) {
_debugMeshes = enabled; _debugMeshes = enabled;
} }
bool SkeletonRenderer::getDebugMeshesEnabled() const { bool SkeletonRendererCocos2dX::getDebugMeshesEnabled() const {
return _debugMeshes; return _debugMeshes;
} }
void SkeletonRenderer::setDebugBoundingRectEnabled(bool enabled) { void SkeletonRendererCocos2dX::setDebugBoundingRectEnabled(bool enabled) {
_debugBoundingRect = enabled; _debugBoundingRect = enabled;
} }
bool SkeletonRenderer::getDebugBoundingRectEnabled() const { bool SkeletonRendererCocos2dX::getDebugBoundingRectEnabled() const {
return _debugBoundingRect; return _debugBoundingRect;
} }
void SkeletonRenderer::onEnter() { void SkeletonRendererCocos2dX::onEnter() {
#if CC_ENABLE_SCRIPT_BINDING && COCOS2D_VERSION < 0x00040000 #if CC_ENABLE_SCRIPT_BINDING && COCOS2D_VERSION < 0x00040000
if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return; if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return;
#endif #endif
@ -781,7 +781,7 @@ namespace spine {
scheduleUpdate(); scheduleUpdate();
} }
void SkeletonRenderer::onExit() { void SkeletonRendererCocos2dX::onExit() {
#if CC_ENABLE_SCRIPT_BINDING && COCOS2D_VERSION < 0x00040000 #if CC_ENABLE_SCRIPT_BINDING && COCOS2D_VERSION < 0x00040000
if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit)) return; if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit)) return;
#endif #endif
@ -791,19 +791,19 @@ namespace spine {
// --- CCBlendProtocol // --- CCBlendProtocol
const BlendFunc &SkeletonRenderer::getBlendFunc() const { const BlendFunc &SkeletonRendererCocos2dX::getBlendFunc() const {
return _blendFunc; return _blendFunc;
} }
void SkeletonRenderer::setBlendFunc(const BlendFunc &blendFunc) { void SkeletonRendererCocos2dX::setBlendFunc(const BlendFunc &blendFunc) {
_blendFunc = blendFunc; _blendFunc = blendFunc;
} }
void SkeletonRenderer::setOpacityModifyRGB(bool value) { void SkeletonRendererCocos2dX::setOpacityModifyRGB(bool value) {
_premultipliedAlpha = value; _premultipliedAlpha = value;
} }
bool SkeletonRenderer::isOpacityModifyRGB() const { bool SkeletonRendererCocos2dX::isOpacityModifyRGB() const {
return _premultipliedAlpha; return _premultipliedAlpha;
} }

View File

@ -38,13 +38,13 @@ namespace spine {
class AttachmentVertices; class AttachmentVertices;
/* Draws a skeleton. */ /* Draws a skeleton. */
class SkeletonRenderer : public cocos2d::Node, public cocos2d::BlendProtocol { class SkeletonRendererCocos2dX : public cocos2d::Node, public cocos2d::BlendProtocol {
public: public:
CREATE_FUNC(SkeletonRenderer); CREATE_FUNC(SkeletonRendererCocos2dX);
static SkeletonRenderer *createWithSkeleton(Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false); static SkeletonRendererCocos2dX *createWithSkeleton(Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false);
static SkeletonRenderer *createWithData(SkeletonData *skeletonData, bool ownsSkeletonData = false); static SkeletonRendererCocos2dX *createWithData(SkeletonData *skeletonData, bool ownsSkeletonData = false);
static SkeletonRenderer *createWithFile(const std::string &skeletonDataFile, Atlas *atlas, float scale = 1); static SkeletonRendererCocos2dX *createWithFile(const std::string &skeletonDataFile, Atlas *atlas, float scale = 1);
static SkeletonRenderer *createWithFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale = 1); static SkeletonRendererCocos2dX *createWithFile(const std::string &skeletonDataFile, const std::string &atlasFile, float scale = 1);
void update(float deltaTime) override; void update(float deltaTime) override;
void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t transformFlags) override; void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t transformFlags) override;
@ -111,13 +111,13 @@ namespace spine {
void setOpacityModifyRGB(bool value) override; void setOpacityModifyRGB(bool value) override;
bool isOpacityModifyRGB() const override; bool isOpacityModifyRGB() const override;
CC_CONSTRUCTOR_ACCESS : SkeletonRenderer(); CC_CONSTRUCTOR_ACCESS : SkeletonRendererCocos2dX();
SkeletonRenderer(Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false); SkeletonRendererCocos2dX(Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false);
SkeletonRenderer(SkeletonData *skeletonData, bool ownsSkeletonData = false); SkeletonRendererCocos2dX(SkeletonData *skeletonData, bool ownsSkeletonData = false);
SkeletonRenderer(const std::string &skeletonDataFile, Atlas *atlas, float scale = 1); SkeletonRendererCocos2dX(const std::string &skeletonDataFile, Atlas *atlas, float scale = 1);
SkeletonRenderer(const std::string &skeletonDataFile, const std::string &atlasFile, float scale = 1); SkeletonRendererCocos2dX(const std::string &skeletonDataFile, const std::string &atlasFile, float scale = 1);
virtual ~SkeletonRenderer(); virtual ~SkeletonRendererCocos2dX();
void initWithSkeleton(Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false); void initWithSkeleton(Skeleton *skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false, bool ownsAtlas = false);
void initWithData(SkeletonData *skeletonData, bool ownsSkeletonData = false); void initWithData(SkeletonData *skeletonData, bool ownsSkeletonData = false);
@ -147,7 +147,7 @@ namespace spine {
bool _debugBones; bool _debugBones;
bool _debugMeshes; bool _debugMeshes;
bool _debugBoundingRect; bool _debugBoundingRect;
SkeletonClipping *_clipper; SkeletonClipping *_clipper;
cocos2d::Rect _boundingRect; cocos2d::Rect _boundingRect;
int _startSlotIndex; int _startSlotIndex;

View File

@ -33,7 +33,7 @@
#include "cocos2d.h" #include "cocos2d.h"
#include <spine/spine.h> #include <spine/spine.h>
#include <spine/SkeletonRenderer.h> #include <spine/SkeletonRendererCocos2dX.h>
#if COCOS2D_VERSION < 0x00040000 #if COCOS2D_VERSION < 0x00040000
#include <spine/v3/SkeletonBatch.h> #include <spine/v3/SkeletonBatch.h>