fix add display

This commit is contained in:
2youyou2 2013-09-23 16:48:09 +08:00
parent e1acbb6af4
commit 90d7abb3ca
5 changed files with 95 additions and 83 deletions

View File

@ -261,18 +261,12 @@ void Armature::addBone(Bone *bone, const char *parentName)
} }
else else
{ {
if (_parentBone) _topBoneList->addObject(bone);
_parentBone->addChildBone(bone);
else
_topBoneList->addObject(bone);
} }
} }
else else
{ {
if (_parentBone) _topBoneList->addObject(bone);
_parentBone->addChildBone(bone);
else
_topBoneList->addObject(bone);
} }
bone->setArmature(this); bone->setArmature(this);
@ -338,7 +332,7 @@ Dictionary *Armature::getBoneDic()
return _boneDic; return _boneDic;
} }
const AffineTransform& Armature::getNodeToParentTransform() const const AffineTransform &Armature::getNodeToParentTransform() const
{ {
if (_transformDirty) if (_transformDirty)
{ {
@ -387,16 +381,16 @@ const AffineTransform& Armature::getNodeToParentTransform() const
// Build Transform Matrix // Build Transform Matrix
// Adjusted transform calculation for rotational skew // Adjusted transform calculation for rotational skew
_transform = AffineTransformMake( cy * _scaleX, sy * _scaleX, _transform = AffineTransformMake( cy * _scaleX, sy * _scaleX,
-sx * _scaleY, cx * _scaleY, -sx * _scaleY, cx * _scaleY,
x, y ); x, y );
// XXX: Try to inline skew // XXX: Try to inline skew
// If skew is needed, apply skew and then anchor point // If skew is needed, apply skew and then anchor point
if (needsSkewMatrix) if (needsSkewMatrix)
{ {
AffineTransform skewMatrix = AffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(_skewY)), AffineTransform skewMatrix = AffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(_skewY)),
tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1.0f, tanf(CC_DEGREES_TO_RADIANS(_skewX)), 1.0f,
0.0f, 0.0f ); 0.0f, 0.0f );
_transform = AffineTransformConcat(skewMatrix, _transform); _transform = AffineTransformConcat(skewMatrix, _transform);
// adjust anchor point // adjust anchor point
@ -452,7 +446,7 @@ void Armature::update(float dt)
Object *object = NULL; Object *object = NULL;
CCARRAY_FOREACH(_topBoneList, object) CCARRAY_FOREACH(_topBoneList, object)
{ {
static_cast<Bone*>(object)->update(dt); static_cast<Bone *>(object)->update(dt);
} }
_armatureTransformDirty = false; _armatureTransformDirty = false;
@ -523,6 +517,8 @@ void Armature::draw()
} }
} }
armature->draw(); armature->draw();
_atlas = armature->getTextureAtlas();
} }
break; break;
default: default:
@ -679,7 +675,7 @@ Bone *Armature::getBoneAtPoint(float x, float y)
for(int i = length - 1; i >= 0; i--) for(int i = length - 1; i >= 0; i--)
{ {
bs = static_cast<Bone*>( _children->getObjectAtIndex(i) ); bs = static_cast<Bone *>( _children->getObjectAtIndex(i) );
if(bs->getDisplayManager()->containPoint(x, y)) if(bs->getDisplayManager()->containPoint(x, y))
{ {
return bs; return bs;

View File

@ -165,6 +165,13 @@ void Bone::update(float delta)
if (_parentBone) if (_parentBone)
_boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty(); _boneTransformDirty = _boneTransformDirty || _parentBone->isTransformDirty();
CCBone *armatureParentBone = _armature->getParentBone();
if (armatureParentBone && !_boneTransformDirty)
{
_boneTransformDirty = armatureParentBone->isTransformDirty();
}
if (_boneTransformDirty) if (_boneTransformDirty)
{ {
if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED) if (_armature->getArmatureData()->dataVersion >= VERSION_COMBINED)
@ -182,6 +189,13 @@ void Bone::update(float delta)
{ {
_worldTransform = AffineTransformConcat(_worldTransform, _parentBone->_worldTransform); _worldTransform = AffineTransformConcat(_worldTransform, _parentBone->_worldTransform);
} }
else
{
if (armatureParentBone)
{
_worldTransform = CCAffineTransformConcat(_worldTransform, armatureParentBone->getNodeToArmatureTransform());
}
}
} }
DisplayFactory::updateDisplay(this, _displayManager->getCurrentDecorativeDisplay(), delta, _boneTransformDirty || _armature->getArmatureTransformDirty()); DisplayFactory::updateDisplay(this, _displayManager->getCurrentDecorativeDisplay(), delta, _boneTransformDirty || _armature->getArmatureTransformDirty());
@ -211,15 +225,15 @@ void Bone::updateDisplayedOpacity(GLubyte parentOpacity)
updateColor(); updateColor();
} }
void Bone::setColor(const Color3B& color) void Bone::setColor(const Color3B &color)
{ {
CCNodeRGBA::setColor(color); CCNodeRGBA::setColor(color);
updateColor(); updateColor();
} }
void Bone::setOpacity(GLubyte opacity) void Bone::setOpacity(GLubyte opacity)
{ {
CCNodeRGBA::setOpacity(opacity); CCNodeRGBA::setOpacity(opacity);
updateColor(); updateColor();
} }
void Bone::updateColor() void Bone::updateColor()

View File

@ -135,6 +135,7 @@ void DisplayManager::addDisplay(Node *display, int index)
if (SpriteDisplayData *spriteDisplayData = (SpriteDisplayData *)decoDisplay->getDisplayData()) if (SpriteDisplayData *spriteDisplayData = (SpriteDisplayData *)decoDisplay->getDisplayData())
{ {
skin->setSkinData(spriteDisplayData->skinData); skin->setSkinData(spriteDisplayData->skinData);
((CCSpriteDisplayData *)displayData)->skinData = spriteDisplayData->skinData;
} }
else else
{ {
@ -256,8 +257,8 @@ void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay)
if (RGBAProtocol *rgbaProtocaol = dynamic_cast<RGBAProtocol *>(_displayRenderNode)) if (RGBAProtocol *rgbaProtocaol = dynamic_cast<RGBAProtocol *>(_displayRenderNode))
{ {
rgbaProtocaol->setColor(_bone->getDisplayedColor()); rgbaProtocaol->setColor(_bone->getDisplayedColor());
rgbaProtocaol->setOpacity(_bone->getDisplayedOpacity()); rgbaProtocaol->setOpacity(_bone->getDisplayedOpacity());
} }
_displayRenderNode->retain(); _displayRenderNode->retain();

View File

@ -84,10 +84,10 @@ bool Skin::initWithSpriteFrameName(const char *pszSpriteFrameName)
if (ret) if (ret)
{ {
TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture);
setTextureAtlas(atlas); setTextureAtlas(atlas);
_displayName = pszSpriteFrameName; _displayName = pszSpriteFrameName;
} }
return ret; return ret;
@ -99,10 +99,10 @@ bool Skin::initWithFile(const char *pszFilename)
if (ret) if (ret)
{ {
TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture); TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture);
setTextureAtlas(atlas); setTextureAtlas(atlas);
_displayName = pszFilename; _displayName = pszFilename;
} }
return ret; return ret;
@ -118,6 +118,7 @@ void Skin::setSkinData(const BaseData &var)
setPosition(Point(_skinData.x, _skinData.y)); setPosition(Point(_skinData.x, _skinData.y));
_skinTransform = getNodeToParentTransform(); _skinTransform = getNodeToParentTransform();
updateArmatureTransform();
} }
const BaseData &Skin::getSkinData() const const BaseData &Skin::getSkinData() const

View File

@ -136,7 +136,7 @@ static const char *CONFIG_FILE_PATH = "config_file_path";
NS_CC_EXT_ARMATURE_BEGIN NS_CC_EXT_ARMATURE_BEGIN
std::vector<std::string> s_arrConfigFileList; std::vector<std::string> s_arrConfigFileList;
float s_PositionReadScale = 1; float s_PositionReadScale = 1;
static float s_FlashToolVersion = VERSION_2_0; static float s_FlashToolVersion = VERSION_2_0;
static float s_CocoStudioVersion = VERSION_COMBINED; static float s_CocoStudioVersion = VERSION_COMBINED;
@ -169,8 +169,8 @@ void DataReaderHelper::loadData()
} }
else else
{ {
std::unique_lock<std::mutex> lk(_sleepMutex); std::unique_lock<std::mutex> lk(_sleepMutex);
_sleepCondition.wait(lk); _sleepCondition.wait(lk);
continue; continue;
} }
} }
@ -243,12 +243,12 @@ void DataReaderHelper::clear()
} }
DataReaderHelper::DataReaderHelper() DataReaderHelper::DataReaderHelper()
: _loadingThread(nullptr) : _loadingThread(nullptr)
, _asyncStructQueue(nullptr) , _asyncStructQueue(nullptr)
, _dataQueue(nullptr) , _dataQueue(nullptr)
, need_quit(false) , need_quit(false)
, _asyncRefCount(0) , _asyncRefCount(0)
, _asyncRefTotalCount(0) , _asyncRefTotalCount(0)
{ {
} }
@ -257,11 +257,11 @@ DataReaderHelper::~DataReaderHelper()
{ {
need_quit = true; need_quit = true;
_sleepCondition.notify_one(); _sleepCondition.notify_one();
if (_loadingThread) _loadingThread->join(); if (_loadingThread) _loadingThread->join();
CC_SAFE_DELETE(_loadingThread); CC_SAFE_DELETE(_loadingThread);
_dataReaderHelper = NULL; _dataReaderHelper = NULL;
} }
void DataReaderHelper::addDataFromFile(const char *filePath) void DataReaderHelper::addDataFromFile(const char *filePath)
@ -354,15 +354,15 @@ void DataReaderHelper::addDataFromFileAsync(const char *filePath, Object *target
_asyncStructQueue = new std::queue<AsyncStruct *>(); _asyncStructQueue = new std::queue<AsyncStruct *>();
_dataQueue = new std::queue<DataInfo *>(); _dataQueue = new std::queue<DataInfo *>();
// create a new thread to load images // create a new thread to load images
_loadingThread = new std::thread(&DataReaderHelper::loadData, this); _loadingThread = new std::thread(&DataReaderHelper::loadData, this);
need_quit = false; need_quit = false;
} }
if (0 == _asyncRefCount) if (0 == _asyncRefCount)
{ {
Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this, 0, false); Director::getInstance()->getScheduler()->scheduleSelector(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this, 0, false);
} }
++_asyncRefCount; ++_asyncRefCount;
@ -854,26 +854,26 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *mov
} }
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity) //! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
CCFrameData **frames = (CCFrameData **)movBoneData->frameList.data->arr; CCFrameData **frames = (CCFrameData **)movBoneData->frameList.data->arr;
for (int i = movBoneData->frameList.count() - 1; i >= 0; i--) for (int i = movBoneData->frameList.count() - 1; i >= 0; i--)
{ {
if (i > 0) if (i > 0)
{ {
float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; float difSkewX = frames[i]->skewX - frames[i - 1]->skewX;
float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; float difSkewY = frames[i]->skewY - frames[i - 1]->skewY;
if (difSkewX < -M_PI || difSkewX > M_PI) if (difSkewX < -M_PI || difSkewX > M_PI)
{ {
frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI;
} }
if (difSkewY < -M_PI || difSkewY > M_PI) if (difSkewY < -M_PI || difSkewY > M_PI)
{ {
frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI;
} }
} }
} }
// //
@ -1429,29 +1429,29 @@ MovementBoneData *DataReaderHelper::decodeMovementBone(cs::JsonDictionary &json)
} }
if (s_CocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE) if (s_CocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE)
{ {
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity) //! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
CCFrameData **frames = (CCFrameData **)movementBoneData->frameList.data->arr; CCFrameData **frames = (CCFrameData **)movementBoneData->frameList.data->arr;
for (int i = movementBoneData->frameList.count() - 1; i >= 0; i--) for (int i = movementBoneData->frameList.count() - 1; i >= 0; i--)
{ {
if (i > 0) if (i > 0)
{ {
float difSkewX = frames[i]->skewX - frames[i - 1]->skewX; float difSkewX = frames[i]->skewX - frames[i - 1]->skewX;
float difSkewY = frames[i]->skewY - frames[i - 1]->skewY; float difSkewY = frames[i]->skewY - frames[i - 1]->skewY;
if (difSkewX < -M_PI || difSkewX > M_PI) if (difSkewX < -M_PI || difSkewX > M_PI)
{ {
frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI; frames[i - 1]->skewX = difSkewX < 0 ? frames[i - 1]->skewX - 2 * M_PI : frames[i - 1]->skewX + 2 * M_PI;
} }
if (difSkewY < -M_PI || difSkewY > M_PI) if (difSkewY < -M_PI || difSkewY > M_PI)
{ {
frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI; frames[i - 1]->skewY = difSkewY < 0 ? frames[i - 1]->skewY - 2 * M_PI : frames[i - 1]->skewY + 2 * M_PI;
} }
} }
} }
} }
if (s_CocoStudioVersion < VERSION_COMBINED) if (s_CocoStudioVersion < VERSION_COMBINED)
{ {
@ -1478,7 +1478,7 @@ FrameData *DataReaderHelper::decodeFrame(cs::JsonDictionary &json)
frameData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear); frameData->tweenEasing = (CCTweenType)json.getItemIntValue(A_TWEEN_EASING, Linear);
frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0); frameData->displayIndex = json.getItemIntValue(A_DISPLAY_INDEX, 0);
frameData->blendType = (BlendType)json.getItemIntValue(A_BLEND_TYPE, 0); frameData->blendType = (BlendType)json.getItemIntValue(A_BLEND_TYPE, 0);
frameData->isTween = (bool)json.getItemBoolvalue(A_TWEEN_FRAME, true); frameData->isTween = (bool)json.getItemBoolvalue(A_TWEEN_FRAME, true);
const char *event = json.getItemStringValue(A_EVENT); const char *event = json.getItemStringValue(A_EVENT);
if (event != NULL) if (event != NULL)
@ -1531,7 +1531,7 @@ TextureData *DataReaderHelper::decodeTexture(cs::JsonDictionary &json)
ContourData *DataReaderHelper::decodeContour(cs::JsonDictionary &json) ContourData *DataReaderHelper::decodeContour(cs::JsonDictionary &json)
{ {
ContourData *contourData = new ContourData(); ContourData *contourData = new ContourData();
contourData->init(); contourData->init();
int length = json.getArrayItemCount(VERTEX_POINT); int length = json.getArrayItemCount(VERTEX_POINT);
for (int i = length - 1; i >= 0; i--) for (int i = length - 1; i >= 0; i--)