Hello,
so I'm trying to use SFML with box2d .. I created a GameObject class
class GameObject
{
public:
Drawable* drawable;
Shape* shape;
b2Body* body;
void setColor(Color color);
void update();
virtual void draw(RenderWindow* window) = 0;
};
and a box class
class Box: public GameObject
{
public:
RectangleShape rectangle;
Box(b2World* world, b2Vec2 position, b2Vec2 size, b2BodyType type, float density = 1, float friction = 0, uint16 category = 1, uint16 mask= 0xFFFF);
void draw(RenderWindow* window)override;
};
I have a
vector<GameObject*> objects;
and every frame I update and draw the boxes
now the problem is this
if (Keyboard::isKeyPressed(Keyboard::Space))
{
objects.push_back(&Box(&world, b2Vec2(0.0f, 4.0f), b2Vec2(4.0f, 4.0f), b2BodyType::b2_dynamicBody, 1, 0, 2));
}
when I try to draw after I've pressed space the app crashes
here is the draw function
void Box::draw(RenderWindow* window)
{
window->draw(rectangle);
}
any Idea what might be the problem here