Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - nerminsh

Pages: [1]
1
General / Re: SFML and Box2d
« on: November 22, 2020, 07:48:02 am »
Thank You .. that was really helpful.

2
General / SFML and Box2d
« on: November 20, 2020, 06:12:19 pm »
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

Pages: [1]