|
@@ -94,7 +94,7 @@ void _Cocos2dRegionAttachment_dispose (Attachment* self) {
|
|
FREE(self);
|
|
FREE(self);
|
|
}
|
|
}
|
|
|
|
|
|
-void _Cocos2dRegionAttachment_draw (Attachment* attachment, Slot* slot) {
|
|
|
|
|
|
+ccV3F_C4B_T2F_Quad* RegionAttachment_updateQuad (Attachment* attachment, Slot* slot) {
|
|
Cocos2dRegionAttachment* self = SUB_CAST(Cocos2dRegionAttachment, attachment);
|
|
Cocos2dRegionAttachment* self = SUB_CAST(Cocos2dRegionAttachment, attachment);
|
|
Cocos2dSkeleton* skeleton = SUB_CAST(Cocos2dSkeleton, slot->skeleton);
|
|
Cocos2dSkeleton* skeleton = SUB_CAST(Cocos2dSkeleton, slot->skeleton);
|
|
|
|
|
|
@@ -130,12 +130,21 @@ void _Cocos2dRegionAttachment_draw (Attachment* attachment, Slot* slot) {
|
|
quad->br.vertices.x = offset[6] * slot->bone->m00 + offset[7] * slot->bone->m01 + slot->bone->worldX;
|
|
quad->br.vertices.x = offset[6] * slot->bone->m00 + offset[7] * slot->bone->m01 + slot->bone->worldX;
|
|
quad->br.vertices.y = offset[6] * slot->bone->m10 + offset[7] * slot->bone->m11 + slot->bone->worldY;
|
|
quad->br.vertices.y = offset[6] * slot->bone->m10 + offset[7] * slot->bone->m11 + slot->bone->worldY;
|
|
|
|
|
|
|
|
+ return quad;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void _Cocos2dRegionAttachment_draw (Attachment* attachment, Slot* slot) {
|
|
|
|
+ RegionAttachment_updateQuad(attachment, slot);
|
|
|
|
+
|
|
|
|
+ Cocos2dRegionAttachment* self = SUB_CAST(Cocos2dRegionAttachment, attachment);
|
|
|
|
+ Cocos2dSkeleton* skeleton = SUB_CAST(Cocos2dSkeleton, slot->skeleton);
|
|
|
|
+
|
|
// Cocos2d doesn't handle batching for us, so we'll just force a single texture per skeleton.
|
|
// Cocos2d doesn't handle batching for us, so we'll just force a single texture per skeleton.
|
|
skeleton->node->textureAtlas = self->textureAtlas;
|
|
skeleton->node->textureAtlas = self->textureAtlas;
|
|
while (self->textureAtlas.capacity <= skeleton->node->quadCount) {
|
|
while (self->textureAtlas.capacity <= skeleton->node->quadCount) {
|
|
if (![self->textureAtlas resizeCapacity:self->textureAtlas.capacity * 2]) return;
|
|
if (![self->textureAtlas resizeCapacity:self->textureAtlas.capacity * 2]) return;
|
|
}
|
|
}
|
|
- [self->textureAtlas updateQuad:quad atIndex:skeleton->node->quadCount++];
|
|
|
|
|
|
+ [self->textureAtlas updateQuad:&self->quad atIndex:skeleton->node->quadCount++];
|
|
}
|
|
}
|
|
|
|
|
|
RegionAttachment* RegionAttachment_create (const char* name, AtlasRegion* region) {
|
|
RegionAttachment* RegionAttachment_create (const char* name, AtlasRegion* region) {
|
|
@@ -304,7 +313,7 @@ char* _Util_readFile (const char* path, int* length) {
|
|
skeleton->a = self.opacity / (float)255;
|
|
skeleton->a = self.opacity / (float)255;
|
|
|
|
|
|
quadCount = 0;
|
|
quadCount = 0;
|
|
- for (int i = 0, n = skeleton->slotCount; i < n; i++)
|
|
|
|
|
|
+ for (int i = 0, n = skeleton->slotCount; i < n; ++i)
|
|
if (skeleton->slots[i]->attachment) Attachment_draw(skeleton->slots[i]->attachment, skeleton->slots[i]);
|
|
if (skeleton->slots[i]->attachment) Attachment_draw(skeleton->slots[i]->attachment, skeleton->slots[i]);
|
|
if (textureAtlas) [textureAtlas drawNumberOfQuads:quadCount];
|
|
if (textureAtlas) [textureAtlas drawNumberOfQuads:quadCount];
|
|
|
|
|
|
@@ -313,7 +322,7 @@ char* _Util_readFile (const char* path, int* length) {
|
|
ccDrawColor4B(0, 0, 255, 255);
|
|
ccDrawColor4B(0, 0, 255, 255);
|
|
glLineWidth(1);
|
|
glLineWidth(1);
|
|
CGPoint points[4];
|
|
CGPoint points[4];
|
|
- for (int i = 0, n = skeleton->slotCount; i < n; i++) {
|
|
|
|
|
|
+ for (int i = 0, n = skeleton->slotCount; i < n; ++i) {
|
|
if (!skeleton->slots[i]->attachment) continue;
|
|
if (!skeleton->slots[i]->attachment) continue;
|
|
ccV3F_C4B_T2F_Quad* quad = &((Cocos2dRegionAttachment*)skeleton->slots[i]->attachment)->quad;
|
|
ccV3F_C4B_T2F_Quad* quad = &((Cocos2dRegionAttachment*)skeleton->slots[i]->attachment)->quad;
|
|
points[0] = ccp(quad->bl.vertices.x, quad->bl.vertices.y);
|
|
points[0] = ccp(quad->bl.vertices.x, quad->bl.vertices.y);
|
|
@@ -327,7 +336,7 @@ char* _Util_readFile (const char* path, int* length) {
|
|
// Bone lengths.
|
|
// Bone lengths.
|
|
glLineWidth(2);
|
|
glLineWidth(2);
|
|
ccDrawColor4B(255, 0, 0, 255);
|
|
ccDrawColor4B(255, 0, 0, 255);
|
|
- for (int i = 0, n = skeleton->boneCount; i < n; i++) {
|
|
|
|
|
|
+ for (int i = 0, n = skeleton->boneCount; i < n; ++i) {
|
|
Bone *bone = skeleton->bones[i];
|
|
Bone *bone = skeleton->bones[i];
|
|
float x = bone->data->length * bone->m00 + bone->worldX;
|
|
float x = bone->data->length * bone->m00 + bone->worldX;
|
|
float y = bone->data->length * bone->m10 + bone->worldY;
|
|
float y = bone->data->length * bone->m10 + bone->worldY;
|
|
@@ -336,7 +345,7 @@ char* _Util_readFile (const char* path, int* length) {
|
|
// Bone origins.
|
|
// Bone origins.
|
|
ccPointSize(4);
|
|
ccPointSize(4);
|
|
ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
|
|
ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
|
|
- for (int i = 0, n = skeleton->boneCount; i < n; i++) {
|
|
|
|
|
|
+ for (int i = 0, n = skeleton->boneCount; i < n; ++i) {
|
|
Bone *bone = skeleton->bones[i];
|
|
Bone *bone = skeleton->bones[i];
|
|
ccDrawPoint(ccp(bone->worldX, bone->worldY));
|
|
ccDrawPoint(ccp(bone->worldX, bone->worldY));
|
|
if (i == 0) ccDrawColor4B(0, 255, 0, 255);
|
|
if (i == 0) ccDrawColor4B(0, 255, 0, 255);
|
|
@@ -344,6 +353,33 @@ char* _Util_readFile (const char* path, int* length) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+- (CGRect) boundingBox {
|
|
|
|
+ float minX = FLT_MAX, minY = FLT_MAX, maxX = FLT_MIN, maxY = FLT_MIN;
|
|
|
|
+ for (int i = 0; i < skeleton->slotCount; ++i) {
|
|
|
|
+ Slot* slot = skeleton->slots[i];
|
|
|
|
+ Attachment* attachment = slot->attachment;
|
|
|
|
+ if (attachment->type != ATTACHMENT_REGION) continue;
|
|
|
|
+ Cocos2dRegionAttachment* regionAttachment = SUB_CAST(Cocos2dRegionAttachment, attachment);
|
|
|
|
+ minX = fmin(minX, regionAttachment->quad.bl.vertices.x);
|
|
|
|
+ minY = fmin(minY, regionAttachment->quad.bl.vertices.y);
|
|
|
|
+ maxX = fmax(maxX, regionAttachment->quad.bl.vertices.x);
|
|
|
|
+ maxY = fmax(maxY, regionAttachment->quad.bl.vertices.y);
|
|
|
|
+ minX = fmin(minX, regionAttachment->quad.br.vertices.x);
|
|
|
|
+ minY = fmin(minY, regionAttachment->quad.br.vertices.y);
|
|
|
|
+ maxX = fmax(maxX, regionAttachment->quad.br.vertices.x);
|
|
|
|
+ maxY = fmax(maxY, regionAttachment->quad.br.vertices.y);
|
|
|
|
+ minX = fmin(minX, regionAttachment->quad.tl.vertices.x);
|
|
|
|
+ minY = fmin(minY, regionAttachment->quad.tl.vertices.y);
|
|
|
|
+ maxX = fmax(maxX, regionAttachment->quad.tl.vertices.x);
|
|
|
|
+ maxY = fmax(maxY, regionAttachment->quad.tl.vertices.y);
|
|
|
|
+ minX = fmin(minX, regionAttachment->quad.tr.vertices.x);
|
|
|
|
+ minY = fmin(minY, regionAttachment->quad.tr.vertices.y);
|
|
|
|
+ maxX = fmax(maxX, regionAttachment->quad.tr.vertices.x);
|
|
|
|
+ maxY = fmax(maxY, regionAttachment->quad.tr.vertices.y);
|
|
|
|
+ }
|
|
|
|
+ return CGRectMake(minX, minY, maxX - minX, maxY - minY);
|
|
|
|
+}
|
|
|
|
+
|
|
// Convenience methods:
|
|
// Convenience methods:
|
|
|
|
|
|
- (void) setMix:(NSString*)fromName to:(NSString*)toName duration:(float)duration {
|
|
- (void) setMix:(NSString*)fromName to:(NSString*)toName duration:(float)duration {
|