- Đã chỉnh sửa
[Cocos2d-x 3.2] Spine and Box2D, @Nate
Hi Nate!
I'm a newbie but like Spine so much.
I use Cocos2d-x 3.2 final + SPine, but there isn't any toturial a bout spine & cocos2d-x except a small animation test in cpp-test of Cocos2d-x 3.2.
I tried to use Box2D and spine but, I got this bug,
My body is locate in Point (0,0) of world,
like this Hình ảnh bị xóa do không hỗ trợ HTTPS. | Vẫn hiển thị
I can't fix it, here is my code
init() fuction
for (int i = 0; i < skeletonNode->skeleton->slotCount; i++) {
spSlot* slot = skeletonNode->skeleton->slots[i];
if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
b2PolygonShape boxPoly;
boxPoly.SetAsBox(attachment->height/PTM_RATIO,attachment->width/PTM_RATIO);
b2BodyDef boxBodyDef;
//boxBodyDef.position.x = skeletonNode->skeleton->x + slot->bone->worldX;
//boxBodyDef.position.y = skeletonNode->skeleton->y + slot->bone->worldY;
b2Body *box = world->CreateBody(&boxBodyDef);
box->CreateFixture(&boxPoly, 1);
}
skeletonNode->setMix("walk", "jump", 0.2f); // ty di sang ngay mat 0.2f
skeletonNode->setMix("jump", "walk", 0.4f); // ty nhay sang di, mat 0.4
skeletonNode->setAnimation(0, "walk", false);
skeletonNode->addAnimation(0, "jump", false);
skeletonNode->addAnimation(0, "walk", true);
skeletonNode->addAnimation(0, "jump", true, 4);
// skeletonNode->addAnimation(1, "drawOrder", true);
skeletonNode->timeScale = 0.3f;
// skeletonNode->debugBones = true;
//skeletonNode->debugSlots = true;
skeletonNode->update(0);
Size windowSize = Director::getInstance()->getWinSize();
skeletonNode->setPosition(Vec2(windowSize.width / 2, 20));
addChild(skeletonNode);
scheduleUpdate();
and update() function
void HelloWorld::update(float deltaTime)
{
int32 velocityIterations = 8;
int32 positionIterations = 1;
world->Step(deltaTime, velocityIterations, positionIterations);
for (b2Body*body = world->GetBodyList(); body != NULL; body = body->GetNext())
//if (body->GetUserData())
{
for (int i = 0; i < skeletonNode->skeleton->slotCount; i++) {
spSlot *currentSlot = skeletonNode->skeleton->slots[i];
if (currentSlot->attachment->type != ATTACHMENT_REGION)
continue;
float x = currentSlot->bone->worldX / PTM_RATIO;
float y = currentSlot->bone->worldY / PTM_RATIO;
float rot = CC_DEGREES_TO_RADIANS(currentSlot->bone->worldRotation);
body->SetTransform(b2Vec2(x, y), rot);
}
}
world->ClearForces();
world->DrawDebugData();
}
Could you fix it to me, ( Cocos2d-x 3.2 + Spine + box2D)
If it's ok! Will you send me some code of 2 funtion above?
Thank you very much!
Sorry I don't have much time to set this up for you. This Java code might help:
https://github.com/EsotericSoftware/spi ... .java#L113
You might also search the forums, I think some people may have done it already. Otherwise I suggest using a simpler skeleton, with just one attachment. Get that working and then try a more complex skeleton.