Using: Windows 7, SFML, C++
I would like to create an array of balls, and I'm a little confused on the process with the b2Body class.
I have a function
I figured I could create the array like this:
But it complains about the constant size of an array being zero. Thank you for any help =)
I would like to create an array of balls, and I'm a little confused on the process with the b2Body class.
I have a function
Code:
b2Body* makeCirBody(b2World *World, b2BodyType type, sf::Shape &Shape, const sf::Vector2f &Position, const float radius)
{
// Create the body
b2BodyDef def;
def.type = type;
def.position.Set(Position.x/PIXELS_METER, Position.y/PIXELS_METER);
b2Body* Body = World->CreateBody(&def);
// Creating the box2d circle shape (size in pixels)
b2CircleShape circle;
circle.m_p.Set(Position.x/PIXELS_METER, Position.y/PIXELS_METER);
circle.m_radius = radius/PIXELS_METER;
b2FixtureDef fix;
fix.shape = &circle;
fix.density = 1.0f;
fix.friction = .0f;
fix.restitution = 1.0f;
b2Vec2 force = b2Vec2(10, 10);
Body->ApplyLinearImpulse(force, def.position);
Body->CreateFixture(&fix);
Shape = sf::Shape::Circle(Position, radius, sf::Color::White);
return Body;
}
{
// Create the body
b2BodyDef def;
def.type = type;
def.position.Set(Position.x/PIXELS_METER, Position.y/PIXELS_METER);
b2Body* Body = World->CreateBody(&def);
// Creating the box2d circle shape (size in pixels)
b2CircleShape circle;
circle.m_p.Set(Position.x/PIXELS_METER, Position.y/PIXELS_METER);
circle.m_radius = radius/PIXELS_METER;
b2FixtureDef fix;
fix.shape = &circle;
fix.density = 1.0f;
fix.friction = .0f;
fix.restitution = 1.0f;
b2Vec2 force = b2Vec2(10, 10);
Body->ApplyLinearImpulse(force, def.position);
Body->CreateFixture(&fix);
Shape = sf::Shape::Circle(Position, radius, sf::Color::White);
return Body;
}
I figured I could create the array like this:
Code:
sf::Shape Balls[200];
b2Body *bBody[200];
for(int i=0;i<200;i++)
b2Body *bBody[i] = makeCirBody(&World, b2_dynamicBody, Balls[i], sf::Vector2f(100,100),15);
b2Body *bBody[200];
for(int i=0;i<200;i++)
b2Body *bBody[i] = makeCirBody(&World, b2_dynamicBody, Balls[i], sf::Vector2f(100,100),15);
But it complains about the constant size of an array being zero. Thank you for any help =)