本文主要是介绍cocostudio骨骼动画 -- 原点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、如果把一个元素如CCSprite加入到CCArmature中,那么必须先要知道CCArmature的原点位置,
经过测试发现:原点大致在(下图所示),x居中,y位于底部。
2、
CCArmature本身继承与CCNode,所以可以设置
锚点和位置,但是CCArmature的大小,也可以说是上下左右的边界如何计算还不是很明白。
看下面的代码:
void CCArmature::updateOffsetPoint()
{// Set contentsize and Calculate anchor point.CCRect rect = boundingBox(); //计算大小setContentSize(rect.size);m_pOffsetPoint = ccp(-rect.origin.x, -rect.origin.y);if (rect.size.width != 0 && rect.size.height != 0){setAnchorPoint(ccp(m_pOffsetPoint.x / rect.size.width, m_pOffsetPoint.y / rect.size.height));}
}
-->>
CCRect CCSkeleton::boundingBox () {float minX = FLT_MAX, minY = FLT_MAX, maxX = FLT_MIN, maxY = FLT_MIN;float scaleX = getScaleX();float scaleY = getScaleY();float vertices[8];for (int i = 0; i < skeleton->slotCount; ++i) {Slot* slot = skeleton->slots[i];if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;RegionAttachment* attachment = (RegionAttachment*)slot->attachment;RegionAttachment_computeVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices);minX = min(minX, vertices[VERTEX_X1] * scaleX);minY = min(minY, vertices[VERTEX_Y1] * scaleY);maxX = max(maxX, vertices[VERTEX_X1] * scaleX);maxY = max(maxY, vertices[VERTEX_Y1] * scaleY);minX = min(minX, vertices[VERTEX_X4] * scaleX);minY = min(minY, vertices[VERTEX_Y4] * scaleY);maxX = max(maxX, vertices[VERTEX_X4] * scaleX);maxY = max(maxY, vertices[VERTEX_Y4] * scaleY);minX = min(minX, vertices[VERTEX_X2] * scaleX);minY = min(minY, vertices[VERTEX_Y2] * scaleY);maxX = max(maxX, vertices[VERTEX_X2] * scaleX);maxY = max(maxY, vertices[VERTEX_Y2] * scaleY);minX = min(minX, vertices[VERTEX_X3] * scaleX);minY = min(minY, vertices[VERTEX_Y3] * scaleY);maxX = max(maxX, vertices[VERTEX_X3] * scaleX);maxY = max(maxY, vertices[VERTEX_Y3] * scaleY);}CCPoint position = getPosition();return CCRectMake(position.x + minX, position.y + minY, maxX - minX, maxY - minY);
}
这篇关于cocostudio骨骼动画 -- 原点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!