Move Sprite with physic body

  • dev dnt
    Likes 0

    Problem Description

    Hi everyone!

    I got a game object (Sprite ) like a box with physic body create by PhysicsBody::createBox() and set this body to that sprite
    my problem is when game update i set position :

    Vec2 item_pos = item->getPosition();

            item_pos.x -= speed * delta;

            item->setPosition(item_pos);

    it move nice rigth to left screen with it’s physic body

    but if i set position by this way

    Vec2 item_pos = item->getPosition();

            item_pos.x = -screen_width

            item->setPosition(item_pos);

    The sprite move out but the body. what is problem here or am i missing something.
    Thank!!!!

  • Sonar Systems admin
    Likes 0

    How have you attached the body to the sprite?

Login to reply