Hi, my name is luis manon
I am creating a 2d Game, and I am currently trying to add spine 2d Slots object to Box2D world body list.
Now I am not able to iterate through the slots of my skeleton I need a little help.
This is my code.
//first since we have assing all the values to our class variable atributes lets
//create our spine 2d sprite
object = Atlas_createFromFile(atlasPath, 0);
//our object atlas will have an skeleton
skeletonObject = SkeletonJson_create(object);
//now we can scale our skeleton object to fit the size in the scree animation
skeletonObject->scale = 0.4f;
//also another attribute the data of our skeleton
dataSkeleton = SkeletonJson_readSkeletonDataFile(skeletonObject, atlasJsonPath);
if (!dataSkeleton)
{
printf("error = %s ", skeletonObject->error);
exit(0);
}
printf("succesfully loaded json ");
//if we successfully upload the skeleton data sprite lets now continue
//now lets dispose the skeleton json object
SkeletonJson_dispose(skeletonObject);
//create our skeletons Bounds this create our AABB and other potential boundaries for our sprite
bound = SkeletonBounds_create();
//set the animation state data of our sprite
stateData = AnimationStateData_create(dataSkeleton);
//AnimationStateData_setMixByName(stateData, "idle", "apple_saiyan", 0.2f);
//AnimationStateData_setMixByName(stateData, "jump", "run", 0.2f);
//they have a drawable image , now since we update all the data lets get ready to make a drawable object for sfml
drawable = new SkeletonDrawable(dataSkeleton, stateData);
//this animation can be change to adjust the events right now the animation iteration
//will work with a time skale of 1 if you want to make it run faster you can make the time
//scale more than 1 and slower is less than 1
drawable->timeScale = 0.5;
//skeleton bonds this will be the pointer to provide the x position and y position of
//character now lets put our drawable to the skeleton object
skeleton = drawable->skeleton;
//now this skeleton object allows us to give x and y position to our spine object
skeleton->flipX = false; //you can flip the x to get different direction
skeleton->flipY = false; //same thing with the y
Skeleton_setToSetupPose(skeleton); //se the pose to be fix up
//now lets give our x and y position for the screen
skeleton->x = _x;
skeleton->y = _y;
//now we update it to the world transformation
Skeleton_updateWorldTransform(skeleton);
//head slot pointer lets construct it
headSlot = Skeleton_findSlot(skeleton, headSlt);
std::list<Slot*>::iterator it = skeleton->slots;
//let me add each one of this player slot to physics body on box2D
//i want to get all the skeleton slot in a loop and find it then add a box2d object to them
b2BodyDef BodyD;
BodyD.position = b2Vec2(skeleton->x / 30.0f, skeleton->y / 30.0f);
BodyD.type = b2_staticBody;
b2Body* Body = game->getBox2dWorldObject()->CreateBody(&BodyD);
b2PolygonShape Shape;
Shape.SetAsBox((32.f / 2) / 30.0f, (32.f / 2) / 30.0f);
b2FixtureDef FixtureDef;
//box now have density
FixtureDef.density = 0;
//also it has friction lol so it stop the box from keeping on moving
FixtureDef.friction = 0.0f;
FixtureDef.shape = &Shape;
//then we create the body fixture
Body->CreateFixture(&FixtureDef);
//we can now output the drawable state with this pointer to keep track of object animation
//drawable->state->listener = callback;
AnimationState_setAnimationByName(drawable->state, 0, "idle", true);
AnimationState_setAnimationByName(drawable->state, 1, "idle", true);