I am engaged on a small platform recreation utilizing box2d.
Once I create the sport’s objects I retailer them inside a vector. One for dynamic our bodies and one for static our bodies.
auto static_obj = Manufacturing facility<StaticObject>::create(identify, place, world);
auto dynamic_obj = Manufacturing facility<DynamicObject>::create(identify, place, world);
if (static_obj)
static_objects.push_back(std::transfer(static_obj));
else if (dynamic_obj)
dynamic_objects.push_back(std::transfer(dynamic_obj));
Afterwards when the sport begins I’ve to drag the dynamic our bodies from the world and replace the visible a part of the objects.
for (b2Body* BodyIterator = m_world->GetBodyList(); BodyIterator != 0; BodyIterator = BodyIterator->GetNext())
{
if (BodyIterator->GetType() == b2_dynamicBody || BodyIterator->GetType() == b2_kinematicBody)
{
auto knowledge = (GameObject*)BodyIterator->GetUserData().pointer;
if (knowledge)
{
if (data->get_name() == "moving_platform")
{
m_dynamic_objects[counter]->update_position(SCALE * BodyIterator->GetPosition().x - 16, SCALE * BodyIterator->GetPosition().y - 25);
m_dynamic_objects[counter]->update_rotation(BodyIterator->GetAngle() * 180 / b2_pi);
counter++;
}
else if (data->get_name() == "participant")
{
m_dynamic_objects[counter]->update_position(SCALE * BodyIterator->GetPosition().x, SCALE * BodyIterator->GetPosition().y);
m_dynamic_objects[counter]->update_rotation(BodyIterator->GetAngle() * 180 / b2_pi);
counter++;
}
}
}
However the issue is that there isn’t a synchronization between the order of the objects on the earth and their order within the vector.
Is there any order of objects throughout the world or is it simply random? And if that’s the case, how can my downside be addressed?