Hey everyone,
I'm having a problem properly creating Box2d bodies on my animation. I've followed the Java tutorial but, and this is probably me, but I'm clearly losing something in translation.
As you can see from the screenshot I've attached above, the bodies aren't in the right spot and don't reflect the shape of the animation. Below is the code I'm using to set up the bodies.
for (int i = 0; i < this->skeleton->slotCount; i++) {
Slot* slot = this->skeleton->slots[i];
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
CCLog("Adding body shape: %s, width: %f, height: %f", attachment->super.name, attachment->width * attachment->scaleX, attachment->height * attachment->scaleY);
b2PolygonShape boxPoly;
boxPoly.SetAsBox(attachment->regionWidth / PTM_RATIO,
attachment->regionHeight / PTM_RATIO,
b2Vec2((attachment->x + attachment->regionOffsetX) / PTM_RATIO, (attachment->y + attachment->regionOffsetY) / PTM_RATIO),
attachment->rotation*3.14159265/180);
b2BodyDef boxBodyDef;
b2Body *box = world->CreateBody(&boxBodyDef);
box->CreateFixture(&boxPoly, 1);
}
The screen shot below shows the actual attachments with debugSlots set to true.
Can anyone help with this? I've been beating my head against this for a couple of days now and this is the closest I've gotten to having anything. Any help would be extremely appreciated.