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骨骼动画 -- 原点全部内容,希望文章能够帮你解决cocostudio骨骼动画 -- 原点所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)