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); }原文链接:https://www.f2er.com/cocos2dx/343782.html