mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
Added CCRGBAProtocol and CCBlendProtocol to CCSkeleton. Fixed issue #20.
This commit is contained in:
parent
e4e8089340
commit
41b748ef4d
@ -215,15 +215,6 @@
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
2FEE852B170030EC0013E4C9 /* spine */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2FEE8585170033120013E4C9 /* spine-cocos2dx */,
|
||||
2FEE85841700330E0013E4C9 /* spine-cpp */,
|
||||
);
|
||||
name = spine;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
2FEE85841700330E0013E4C9 /* spine-cpp */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -339,7 +330,8 @@
|
||||
BF23D4E2143315EB00657E08 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2FEE852B170030EC0013E4C9 /* spine */,
|
||||
2FEE85841700330E0013E4C9 /* spine-cpp */,
|
||||
2FEE8585170033120013E4C9 /* spine-cocos2dx */,
|
||||
2FEE8522170030A20013E4C9 /* AppDelegate.cpp */,
|
||||
2FEE8523170030A20013E4C9 /* AppDelegate.h */,
|
||||
2FEE8524170030A20013E4C9 /* AppMacros.h */,
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
type = "1"
|
||||
version = "1.0">
|
||||
</Bucket>
|
||||
@ -15,7 +15,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||
// create the application instance
|
||||
AppDelegate app;
|
||||
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
|
||||
eglView->setViewName("ExampleSpine");
|
||||
eglView->setViewName("SpineExample");
|
||||
eglView->setFrameSize(480, 320);
|
||||
// So we need to invoke 'setFrameZoomFactor' (only valid on desktop(win32, mac, linux)) to make the window smaller.
|
||||
// eglView->setFrameZoomFactor(0.4f);
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#ifndef SPINE_CCSKELETON_H_
|
||||
#define SPINE_CCSKELETON_H_
|
||||
|
||||
#include "base_nodes/CCNode.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
namespace spine {
|
||||
|
||||
@ -35,7 +35,7 @@ class Skeleton;
|
||||
class AnimationState;
|
||||
class AnimationStateData;
|
||||
|
||||
class CCSkeleton: public cocos2d::CCNode {
|
||||
class CCSkeleton: public cocos2d::CCNode, public cocos2d::CCRGBAProtocol, public cocos2d::CCBlendProtocol {
|
||||
public:
|
||||
Skeleton *skeleton;
|
||||
AnimationState *state;
|
||||
@ -47,6 +47,17 @@ public:
|
||||
|
||||
virtual void update (float deltaTime);
|
||||
virtual void draw ();
|
||||
|
||||
// CCRGBAProtocol
|
||||
CC_PROPERTY_PASS_BY_REF(cocos2d::ccColor3B, color, Color);
|
||||
cocos2d::ccColor3B colorUnmodified;
|
||||
CC_PROPERTY(GLubyte, opacity, Opacity);
|
||||
bool opacityModifyRGB;
|
||||
bool isOpacityModifyRGB ();
|
||||
void setOpacityModifyRGB (bool isOpacityModifyRGB);
|
||||
|
||||
// CCBlendProtocol
|
||||
CC_PROPERTY(cocos2d::ccBlendFunc, blendFunc, BlendFunc);
|
||||
};
|
||||
|
||||
} /* namespace spine */
|
||||
|
||||
@ -44,11 +44,20 @@ CCSkeleton* CCSkeleton::create (SkeletonData* skeletonData) {
|
||||
}
|
||||
|
||||
CCSkeleton::CCSkeleton (SkeletonData *skeletonData, AnimationStateData *stateData) :
|
||||
opacity(255),
|
||||
opacityModifyRGB(false),
|
||||
debug(false) {
|
||||
if (!skeletonData) throw std::invalid_argument("skeletonData cannot be null.");
|
||||
skeleton = new Skeleton(skeletonData);
|
||||
state = new AnimationState(stateData);
|
||||
|
||||
color.r = 255;
|
||||
color.g = 255;
|
||||
color.b = 255;
|
||||
colorUnmodified = color;
|
||||
blendFunc.src = CC_BLEND_SRC;
|
||||
blendFunc.dst = CC_BLEND_DST;
|
||||
|
||||
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
|
||||
scheduleUpdate();
|
||||
}
|
||||
@ -67,7 +76,12 @@ void CCSkeleton::update (float deltaTime) {
|
||||
|
||||
void CCSkeleton::draw () {
|
||||
CC_NODE_DRAW_SETUP();
|
||||
ccGLBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
ccGLBlendFunc(blendFunc.src, blendFunc.dst);
|
||||
skeleton->r = color.r / (float)255;
|
||||
skeleton->g = color.g / (float)255;
|
||||
skeleton->b = color.b / (float)255;
|
||||
skeleton->a = opacity / (float)255;
|
||||
skeleton->draw();
|
||||
|
||||
if (debug) {
|
||||
@ -103,3 +117,49 @@ void CCSkeleton::draw () {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CCSkeleton - RGBA protocol
|
||||
|
||||
const ccColor3B& CCSkeleton::getColor () {
|
||||
if (opacityModifyRGB) return colorUnmodified;
|
||||
return color;
|
||||
}
|
||||
|
||||
void CCSkeleton::setColor (const ccColor3B& color) {
|
||||
this->color = colorUnmodified = color;
|
||||
if (opacityModifyRGB) {
|
||||
this->color.r = color.r * opacity / 255;
|
||||
this->color.g = color.g * opacity / 255;
|
||||
this->color.b = color.b * opacity / 255;
|
||||
}
|
||||
}
|
||||
|
||||
GLubyte CCSkeleton::getOpacity () {
|
||||
return opacity;
|
||||
}
|
||||
|
||||
void CCSkeleton::setOpacity (GLubyte opacity) {
|
||||
this->opacity = opacity;
|
||||
// Special opacity for premultiplied textures.
|
||||
if (opacityModifyRGB) this->setColor(colorUnmodified);
|
||||
}
|
||||
|
||||
void CCSkeleton::setOpacityModifyRGB (bool isOpacityModifyRGB) {
|
||||
ccColor3B oldColor = this->getColor();
|
||||
opacityModifyRGB = isOpacityModifyRGB;
|
||||
this->setColor(oldColor);
|
||||
}
|
||||
|
||||
bool CCSkeleton::isOpacityModifyRGB () {
|
||||
return opacityModifyRGB;
|
||||
}
|
||||
|
||||
// CCBlendProtocol
|
||||
|
||||
ccBlendFunc CCSkeleton::getBlendFunc () {
|
||||
return blendFunc;
|
||||
}
|
||||
|
||||
void CCSkeleton::setBlendFunc (ccBlendFunc blendFunc) {
|
||||
this->blendFunc = blendFunc;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user